#include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { long long n, z; scanf("%lld %lld", &n, &z); vector<pair<pair<int, int>, int> > v_p, v_0, v_m; vector<int> result; for (int i=0;i<n;i++) { int d, a; scanf("%d %d", &d, &a); if (a==d) v_0.push_back(make_pair(make_pair(d, a-d), i)); if (a<d) v_m.push_back(make_pair(make_pair(a, d), i)); if (a>d) v_p.push_back(make_pair(make_pair(d, a-d), i)); } long long l = z; sort(v_p.begin(),v_p.end()); //reverse(v_p.begin(), v_p.end()); for (int i=0;i<v_p.size();i++) if (l>v_p[i].first.first) {l+=v_p[i].first.second; result.push_back(v_p[i].second);} else {printf("NIE\n"); return 0;} for (int i=0;i<v_0.size();i++) if (l>v_0[i].first.first) {result.push_back(v_0[i].second);} else {printf("NIE\n"); return 0;} sort(v_m.begin(),v_m.end()); reverse(v_m.begin(), v_m.end()); //for (int i=0;i<v_m.size();i++) printf("%d %d\n", v_m[i].first.first, v_m[i].first.second); for (int i=0;i<v_m.size();i++) if (l>v_m[i].first.second) {l+=v_m[i].first.first-v_m[i].first.second; result.push_back(v_m[i].second);} else {printf("NIE\n"); return 0;} printf("TAK\n"); for(int i=0;i<result.size();i++) printf("%d ", result[i]+1); printf("\n"); 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 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { long long n, z; scanf("%lld %lld", &n, &z); vector<pair<pair<int, int>, int> > v_p, v_0, v_m; vector<int> result; for (int i=0;i<n;i++) { int d, a; scanf("%d %d", &d, &a); if (a==d) v_0.push_back(make_pair(make_pair(d, a-d), i)); if (a<d) v_m.push_back(make_pair(make_pair(a, d), i)); if (a>d) v_p.push_back(make_pair(make_pair(d, a-d), i)); } long long l = z; sort(v_p.begin(),v_p.end()); //reverse(v_p.begin(), v_p.end()); for (int i=0;i<v_p.size();i++) if (l>v_p[i].first.first) {l+=v_p[i].first.second; result.push_back(v_p[i].second);} else {printf("NIE\n"); return 0;} for (int i=0;i<v_0.size();i++) if (l>v_0[i].first.first) {result.push_back(v_0[i].second);} else {printf("NIE\n"); return 0;} sort(v_m.begin(),v_m.end()); reverse(v_m.begin(), v_m.end()); //for (int i=0;i<v_m.size();i++) printf("%d %d\n", v_m[i].first.first, v_m[i].first.second); for (int i=0;i<v_m.size();i++) if (l>v_m[i].first.second) {l+=v_m[i].first.first-v_m[i].first.second; result.push_back(v_m[i].second);} else {printf("NIE\n"); return 0;} printf("TAK\n"); for(int i=0;i<result.size();i++) printf("%d ", result[i]+1); printf("\n"); return 0; } |