有点坑,得用64位
#include"stdio.h" #include"algorithm" using namespace std; __int64 cmp(__int64 a,__int64 b) { if(a<b)return 0; else return 1; } int main() { int i; __int64 L,n; __int64 a[604]; while(scanf("%I64d%I64d",&L,&n)!=-1) { for(i=0;i<n;i++) scanf("%I64d",&a[i]); sort(a,a+n,cmp); int ans=0; for(i=0;i<n;i++) { ans+=a[i]; if(ans>=L)break; } if(n==i)printf("impossible\n"); else printf("%d\n",i+1); } return 0; }