POJ 2593
1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 int cmp ( const void *a , const void *b ) 5 { 6 return *(int *)b - *(int *)a; 7 } 8 int main() 9 { 10 int sum,n,flag,i,a[100010]; 11 while (1) 12 { 13 sum=0; 14 flag=0; 15 scanf("%d",&n); 16 if (n==0) 17 break; 18 for (i=0;i<n;i++) 19 { 20 scanf("%d",&a[i]); 21 if (a[i]>0) 22 { 23 flag++; 24 sum+=a[i]; 25 } 26 } 27 if (flag==0||flag==1) 28 { 29 qsort(a,n,sizeof(a[0]),cmp); 30 printf("%d\n",a[0]+a[1]); 31 } 32 else printf("%d\n",sum); 33 } 34 return 0; 35 }