Problem Description
Problem Analysis
In other words, pick as many positive numbers as possible
The only case to watch out for is when there are no positive numbers
Then pick the negative number with the largest value
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| #include<stdio.h>
int main() {
int t,n,i,x,sum,max;
int a[120];
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
for(i=0; i<n; i++)
scanf("%d",&a[i]);
for(i=0,sum=max=x=0; i<n; i++) {
if(a[i]>=0) {
sum=sum+a[i];
x++;
} else {
if(max==0||a[i]>max)
max=a[i];
}
}
if(x==0)
printf("1 %d\n",max);
else
printf("%d %d\n",x,sum);
}
return 0;
}
|
Problem link: [ZZULI][1761]You can do it](http://acm.zzuli.edu.cn/problem.php?id=1761)