#include <cstdio> #include <vector> #include <algorithm> using namespace std; vector<pair<int, int>> data; vector<int> negative, positive; struct sort_positive { bool operator() (int i1, int i2) { return data[i1].first < data[i2].first; }}; struct sort_negative { bool operator() (int i1, int i2) { return data[i1].second > data[i2].second; }}; int main() { int n; long long z; scanf("%d %lld", &n, &z); int c1, c2; for(int i=0;i<n;i++) { scanf("%d %d", &c1, &c2); data.push_back(make_pair(c1, c2)); if(c1>c2) negative.push_back(i); else positive.push_back(i); } sort(positive.begin(), positive.end(), sort_positive()); sort(negative.begin(), negative.end(), sort_negative()); for(auto& p : positive) { long long z1 = z-data[p].first; long long z2 = z1+data[p].second; z = z2; if(z1<=0) { printf("NIE\n"); return 0; } } for(auto& p : negative) { long long z1 = z-data[p].first; long long z2 = z1+data[p].second; z = z2; if(z1<=0) { printf("NIE\n"); return 0; } } printf("TAK\n"); for(auto& p : positive) printf("%d ", p+1); for(auto& p : negative) printf("%d ", p+1); }
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 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; vector<pair<int, int>> data; vector<int> negative, positive; struct sort_positive { bool operator() (int i1, int i2) { return data[i1].first < data[i2].first; }}; struct sort_negative { bool operator() (int i1, int i2) { return data[i1].second > data[i2].second; }}; int main() { int n; long long z; scanf("%d %lld", &n, &z); int c1, c2; for(int i=0;i<n;i++) { scanf("%d %d", &c1, &c2); data.push_back(make_pair(c1, c2)); if(c1>c2) negative.push_back(i); else positive.push_back(i); } sort(positive.begin(), positive.end(), sort_positive()); sort(negative.begin(), negative.end(), sort_negative()); for(auto& p : positive) { long long z1 = z-data[p].first; long long z2 = z1+data[p].second; z = z2; if(z1<=0) { printf("NIE\n"); return 0; } } for(auto& p : negative) { long long z1 = z-data[p].first; long long z2 = z1+data[p].second; z = z2; if(z1<=0) { printf("NIE\n"); return 0; } } printf("TAK\n"); for(auto& p : positive) printf("%d ", p+1); for(auto& p : negative) printf("%d ", p+1); } |