Question Description:
Ram has given an array of integers "A" to Tina, Tina need to find the maximum sum that can be obtained by picking some non-empty subset of the array.
If there are many such non-empty subsets, choose the one with the maximum number of elements.
Print the maximum sum and the number of elements in the chosen subset.
Constraints:
1 ≤ N ≤ 10^5
-10^9 ≤ Ai ≤ 10^9
Input Format:
The first line contains an integer 'N', denoting the number of elements of the array.
#include<stdio.h>
int main(){
long long A[100005],sum=0,max=-1000000000;
int N,i,count=0,num;
scanf("%d",&N);
for(i=0;i<N;i++){
scanf("%lld",&A[i]);
if(A[i]>0){sum+=A[i];count++;}
if(A[i]>max)max=A[i];
}
num=1;
while(num){
if(count)printf("%lld %d",sum,count);
else printf("%lld 1",max);
num=0;
}
}
0 Comments