#include<iostream>
#include<algorithm>
#define Max 602
using namespace std;
int a[Max];
bool cmp(int c, int d)
{
return c > d;
}
int main()
{
int m;
__int64 n, s;
while(scanf("%I64d%d", &n, &m) != EOF)
{
int i;
for( i=0; i < m; i++ )
scanf("%d", &a[i]);
sort(a, a+m, cmp);
s = 0;
for( i=0; i < m; i++ )
{
s += a[i];
if(s >= n)
break;
}
if(i == m)
printf("impossible\n");
else
printf("%d\n", i+1);
}
return 0;
}
hdu 2124 Repair the Wall 贪心
最新推荐文章于 2017-07-30 21:00:32 发布