// http://www.spoj.com/problems/STAMPS/
#include <iostream>
#include <queue>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
int s = 1;
while (t-- >0) {
int target, np;
cin >> target >> np;
priority_queue<int> friends;
for (int i = 0; i <np; i++) {
int stampes;
cin >> stampes;
friends.push(stampes);
}
int borrowed = 0;
int borrowedpeople = 0;
while (borrowed < target && borrowedpeople<np) {
borrowed += friends.top();
friends.pop();
borrowedpeople++;
}
cout << "Scenario #" << s << ":" << endl;
if (borrowed < target) {
cout << "impossible" << endl;
} else {
cout << borrowedpeople << endl;
}
cout << endl;
s++;
}
}
SPOJ STAMPS
最新推荐文章于 2018-10-04 15:40:00 发布