标签:
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <cstring> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <map> #define PI acos(-1.0) #define ms(a) memset(a,0,sizeof(a)) #define msp memset(mp,0,sizeof(mp)) #define msv memset(vis,0,sizeof(vis)) using namespace std; //#define LOCAL int cmp(int a,int b){return a>b;} int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL ios::sync_with_stdio(false); int wall,n; vector<int> v; while(cin>>wall>>n) { v.clear(); int sum=0; for(int i=0;i<n;i++) { int t; cin>>t; sum+=t; v.push_back(t); } if(sum<wall)printf("impossible\n"); else {sort(v.begin(),v.end(),cmp); int ans=0,cnt=0; for(int i=0;i<(int)v.size();i++) { if(cnt>=wall)break; else cnt+=v[i],ans++; } printf("%d\n",ans);} } return 0; }
标签:
原文地址:http://www.cnblogs.com/gpsx/p/5187010.html