#include <iostream> #include <fstream> #include <vector> #include <string> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<PII, int> PIII; typedef vector<PIII> VPIII; typedef vector<int> VI; #define lost first #define gain second #define data first #define id second const int MAX_VAL = 1000000000; VI res; LL curr_points; bool cmp(const PIII& x, const PIII& y) { return x.data.gain > y.data.gain; } void process(VPIII& vals) { for (int i = 0; i < vals.size(); ++i) { curr_points -= vals[i].data.lost; if (curr_points <= 0) { break; } curr_points += vals[i].data.gain; res.push_back(vals[i].id); } } VPIII gains, losts; int main() { int na; cin >> na >> curr_points; gains.reserve(na); losts.reserve(na); res.reserve(na); for (int i = 1; i <= na; ++i) { PII val; cin >> val.lost >> val.gain; PIII entry(val, i); if (val.gain >= val.lost) { gains.push_back(entry); } else { losts.push_back(entry); } } sort(gains.begin(), gains.end()); sort(losts.begin(), losts.end(), cmp); process(gains); if (curr_points > 0) { process(losts); } cout << (curr_points > 0 ? "TAK" : "NIE") << endl; if (curr_points > 0) { cout << res[0]; for (int i = 1; i < res.size(); ++i) { cout << ' ' << res[i]; } cout << endl; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include <iostream> #include <fstream> #include <vector> #include <string> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<PII, int> PIII; typedef vector<PIII> VPIII; typedef vector<int> VI; #define lost first #define gain second #define data first #define id second const int MAX_VAL = 1000000000; VI res; LL curr_points; bool cmp(const PIII& x, const PIII& y) { return x.data.gain > y.data.gain; } void process(VPIII& vals) { for (int i = 0; i < vals.size(); ++i) { curr_points -= vals[i].data.lost; if (curr_points <= 0) { break; } curr_points += vals[i].data.gain; res.push_back(vals[i].id); } } VPIII gains, losts; int main() { int na; cin >> na >> curr_points; gains.reserve(na); losts.reserve(na); res.reserve(na); for (int i = 1; i <= na; ++i) { PII val; cin >> val.lost >> val.gain; PIII entry(val, i); if (val.gain >= val.lost) { gains.push_back(entry); } else { losts.push_back(entry); } } sort(gains.begin(), gains.end()); sort(losts.begin(), losts.end(), cmp); process(gains); if (curr_points > 0) { process(losts); } cout << (curr_points > 0 ? "TAK" : "NIE") << endl; if (curr_points > 0) { cout << res[0]; for (int i = 1; i < res.size(); ++i) { cout << ' ' << res[i]; } cout << endl; } return 0; } |