#include<stdio.h> #include<stdlib.h> #include<string.h> int N; int a[101]; int comp(const void *a,const void *b) { return *(int *)a-*(int *)b; } int main(int argc, char *argv[]) { while(~scanf("%d",&N)) { memset(a,0,sizeof(int)); for(int i=0;i<N;++i) { scanf("%d",&a[i]); } qsort(a,N,sizeof(int),comp); int ans=0; ans = 0; for (int i = 0; i < N; ++i){ if (a[i] > ans + 1){ break; } else ans += a[i]; } printf("%d\n", ans + 1); } return 0; }
原文地址:http://blog.csdn.net/wdkirchhoff/article/details/42030063