SPOJ STAMPS

来源:互联网 发布:大数据时代的营销变革 编辑:程序博客网 时间:2024/05/17 08:09
// 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++;}}

0 0
原创粉丝点击