#include <iostream> #include <cstdlib> #include <vector> #include <algorithm> using namespace std; #define max(a,b) (((a)>(b))?(a):(b)) int N,HP; vector<long long int> D,A; long long int d,a; vector<int> OK; vector<int> SS; vector<int> OUT; struct fajne { bool operator() (int i,int j) { return D[i] < D[j] || D[i] == D[j] && A[i] < A[j]; } } cmp_fajne; struct niefajne { bool operator() (int i,int j) { long long int v1 = max( D[i], D[j] - A[i] ); long long int v2 = max( D[j], D[i] - A[j] ); return (v1<v2); } } cmp_niefajne; int main() { cin >> N >> HP; A.push_back(0); D.push_back(0); for (int i=1; i<=N; ++i) { cin >> d >> a; D.push_back(d); a = a-d; A.push_back(a); if ( a >=0 ) OK.push_back(i); else SS.push_back(i); } sort(OK.begin(), OK.end(), cmp_fajne); sort(SS.begin(), SS.end(), cmp_niefajne); for (int i=0;i<OK.size();++i) { if ( HP - D[OK[i]] > 0 ) { HP = HP + A[OK[i]]; OUT.push_back(OK[i]); } else { cout <<"NIE\n" ; return 0; } } for (int i=0;i<SS.size();++i) { if ( HP - D[SS[i]] > 0 ) { HP = HP + A[SS[i]]; OUT.push_back(SS[i]); } else { cout <<"NIE\n" ; return 0; } } cout <<"TAK\n"; for (int i=0;i<OUT.size();++i) cout << OUT[i] << " "; cout << "\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 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 | #include <iostream> #include <cstdlib> #include <vector> #include <algorithm> using namespace std; #define max(a,b) (((a)>(b))?(a):(b)) int N,HP; vector<long long int> D,A; long long int d,a; vector<int> OK; vector<int> SS; vector<int> OUT; struct fajne { bool operator() (int i,int j) { return D[i] < D[j] || D[i] == D[j] && A[i] < A[j]; } } cmp_fajne; struct niefajne { bool operator() (int i,int j) { long long int v1 = max( D[i], D[j] - A[i] ); long long int v2 = max( D[j], D[i] - A[j] ); return (v1<v2); } } cmp_niefajne; int main() { cin >> N >> HP; A.push_back(0); D.push_back(0); for (int i=1; i<=N; ++i) { cin >> d >> a; D.push_back(d); a = a-d; A.push_back(a); if ( a >=0 ) OK.push_back(i); else SS.push_back(i); } sort(OK.begin(), OK.end(), cmp_fajne); sort(SS.begin(), SS.end(), cmp_niefajne); for (int i=0;i<OK.size();++i) { if ( HP - D[OK[i]] > 0 ) { HP = HP + A[OK[i]]; OUT.push_back(OK[i]); } else { cout <<"NIE\n" ; return 0; } } for (int i=0;i<SS.size();++i) { if ( HP - D[SS[i]] > 0 ) { HP = HP + A[SS[i]]; OUT.push_back(SS[i]); } else { cout <<"NIE\n" ; return 0; } } cout <<"TAK\n"; for (int i=0;i<OUT.size();++i) cout << OUT[i] << " "; cout << "\n"; return 0; } |