// PA2014, runda 2, Bohater // Andrzej Pezarski #include <cstdlib> #include <cstdio> #include <vector> #include <algorithm> #include <numeric> using namespace std; int main() { int n; long long z; scanf("%d%lld", &n, &z); vector<pair <pair<int, int>, int> > A, B; for (int i=1; i<=n; i++) { int d, a; scanf("%d%d", &d, &a); ((d<=a)?A:B).push_back(make_pair(make_pair(d, a), i)); } sort(A.begin(), A.end()); sort(B.begin(), B.end()); reverse(B.begin(), B.end()); for (auto x:A) { z-=x.first.first; if(z<=0) break; z+=x.first.second; } for (auto x:B) { z-=x.first.first; if(z<=0) break; z+=x.first.second; } if (z<=0) printf("NIE\n"); else { printf("TAK\n"); for (auto x:A) printf("%d ", x.second); for (auto x:B) printf("%d ", x.second); 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 | // PA2014, runda 2, Bohater // Andrzej Pezarski #include <cstdlib> #include <cstdio> #include <vector> #include <algorithm> #include <numeric> using namespace std; int main() { int n; long long z; scanf("%d%lld", &n, &z); vector<pair <pair<int, int>, int> > A, B; for (int i=1; i<=n; i++) { int d, a; scanf("%d%d", &d, &a); ((d<=a)?A:B).push_back(make_pair(make_pair(d, a), i)); } sort(A.begin(), A.end()); sort(B.begin(), B.end()); reverse(B.begin(), B.end()); for (auto x:A) { z-=x.first.first; if(z<=0) break; z+=x.first.second; } for (auto x:B) { z-=x.first.first; if(z<=0) break; z+=x.first.second; } if (z<=0) printf("NIE\n"); else { printf("TAK\n"); for (auto x:A) printf("%d ", x.second); for (auto x:B) printf("%d ", x.second); printf("\n"); } return 0; } |