#include<iostream> #include<cstdio> #include<cctype> #include<cmath> #include<cstdlib> #include<algorithm> #include<vector> #include<string> #include<list> #include<deque> #include<map> #include<set> #include<queue> #include<stack> #include<utility> #include<sstream> #include<cstring> using namespace std; #define FOR(I,A,B) for(int I=(A);I<=(B);I++) #define REP(I,N) for(int I=0;I<(N);I++) #define ALL(X) (X).begin(),(X).end() #define PB push_back #define MP make_pair #define FI first #define SE second typedef vector<int> VI; typedef pair<int,int> PII; typedef long long ll; typedef vector<string> VS; #define FORD(I,A,B) for(int I=(A);I>=(B);I--) #define INFTY 100000000 #define VAR(V,init) __typeof(init) V=(init) #define FOREACH(I,C) for(VAR(I,(C).begin());I!=(C).end();I++) #define PRINT1(a) cout << a << endl; #define PRINT2(a, b) cout << a << ": " << b << endl; #define PRINT3(a, b, c) cout << a << ": " << b << ", " << c << endl; #define PRINT4(a, b, c, d) cout << a << ": " << b << ", " << c << ", "<< d << endl; struct less_than_key { inline bool operator() (const pair< PII, int>& struct1, const pair< PII, int>& struct2) { return (struct1.first.first < struct2.first.first); } }; struct less_than_key2 { inline bool operator() (const pair< PII, int>& struct1, const pair< PII, int>& struct2) { return (struct1.first.second < struct2.first.second); } }; int main(){ ios_base::sync_with_stdio(0); int n, z, d, a; cin >> n >> z; //testcases: vector< pair< PII, int> > good; vector< pair< PII, int> > bad; REP(i, n) { cin >> d >> a; if (d <= a) good.push_back(make_pair(make_pair(d, a), i+1)); else bad.push_back(make_pair(make_pair(d, a), i+1)); } sort(ALL(good),less_than_key()); sort(ALL(bad),less_than_key2()); reverse(ALL(bad)); //REP(i, bad.size()) // cout << bad[i].second << ", "; //cout << endl; bool found = true; //symulacja czy ok REP(i, good.size()) { if (z > good[i].first.first) z += (good[i].first.second - good[i].first.first); else found = false; } REP(i, bad.size()) { if (z > bad[i].first.first) z += (bad[i].first.second - bad[i].first.first); else found = false; } if (found) { cout << "TAK" << endl; REP(i, good.size()) cout << good[i].second << " "; REP(i, bad.size()-1) cout << bad[i].second << " "; cout << bad[bad.size()-1].second << endl; } else cout << "NIE" << 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | #include<iostream> #include<cstdio> #include<cctype> #include<cmath> #include<cstdlib> #include<algorithm> #include<vector> #include<string> #include<list> #include<deque> #include<map> #include<set> #include<queue> #include<stack> #include<utility> #include<sstream> #include<cstring> using namespace std; #define FOR(I,A,B) for(int I=(A);I<=(B);I++) #define REP(I,N) for(int I=0;I<(N);I++) #define ALL(X) (X).begin(),(X).end() #define PB push_back #define MP make_pair #define FI first #define SE second typedef vector<int> VI; typedef pair<int,int> PII; typedef long long ll; typedef vector<string> VS; #define FORD(I,A,B) for(int I=(A);I>=(B);I--) #define INFTY 100000000 #define VAR(V,init) __typeof(init) V=(init) #define FOREACH(I,C) for(VAR(I,(C).begin());I!=(C).end();I++) #define PRINT1(a) cout << a << endl; #define PRINT2(a, b) cout << a << ": " << b << endl; #define PRINT3(a, b, c) cout << a << ": " << b << ", " << c << endl; #define PRINT4(a, b, c, d) cout << a << ": " << b << ", " << c << ", "<< d << endl; struct less_than_key { inline bool operator() (const pair< PII, int>& struct1, const pair< PII, int>& struct2) { return (struct1.first.first < struct2.first.first); } }; struct less_than_key2 { inline bool operator() (const pair< PII, int>& struct1, const pair< PII, int>& struct2) { return (struct1.first.second < struct2.first.second); } }; int main(){ ios_base::sync_with_stdio(0); int n, z, d, a; cin >> n >> z; //testcases: vector< pair< PII, int> > good; vector< pair< PII, int> > bad; REP(i, n) { cin >> d >> a; if (d <= a) good.push_back(make_pair(make_pair(d, a), i+1)); else bad.push_back(make_pair(make_pair(d, a), i+1)); } sort(ALL(good),less_than_key()); sort(ALL(bad),less_than_key2()); reverse(ALL(bad)); //REP(i, bad.size()) // cout << bad[i].second << ", "; //cout << endl; bool found = true; //symulacja czy ok REP(i, good.size()) { if (z > good[i].first.first) z += (good[i].first.second - good[i].first.first); else found = false; } REP(i, bad.size()) { if (z > bad[i].first.first) z += (bad[i].first.second - bad[i].first.first); else found = false; } if (found) { cout << "TAK" << endl; REP(i, good.size()) cout << good[i].second << " "; REP(i, bad.size()-1) cout << bad[i].second << " "; cout << bad[bad.size()-1].second << endl; } else cout << "NIE" << endl; return 0; } |