poj2487
简单题
View Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 1005
int stamp[maxn];
bool cmp(const int &a, const int &b)
{
return a > b;
}
int main()
{
//freopen("t.txt", "r", stdin);
int t, n, m;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
scanf("%d%d", &m, &n);
for (int j = 0; j < n; j++)
scanf("%d", &stamp[j]);
sort(stamp, stamp + n, cmp);
int sum = 0;
int num = 0;
for (int j = 0; j < n; j++)
{
num++;
sum += stamp[j];
if (sum >= m)
break;
}
printf("Scenario #%d:\n", i + 1);
if (sum >= m)
printf("%d\n\n", num);
else
printf("impossible\n");
}
return 0;
}