标签:
5 3 3 2 1 5 2 2 1
2 impossible
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<algorithm> using namespace std; const int maxn=600+10; bool cmp(int a,int b) { return a>b; } int main() { int len,n,i,res; int a[maxn]; while(scanf("%d%d",&len,&n)!=EOF) { for(i=0;i<n;i++)scanf("%d",&a[i]); sort(a,a+n,cmp); res=0; for(i=0;i<n;i++) { if(a[i]>=len) { res++; len-=a[i]; break; } else { len-=a[i]; res++; } } if(len>0)printf("impossible\n"); else printf("%d\n",res); } return 0; }
标签:
原文地址:http://www.cnblogs.com/Annetree/p/5510393.html