#include<iostream> #include<algorithm> using namespace std; typedef long long LL; #define REP(i, n) for(int i=0; i<(n); ++i) #define FOR(i, a, n) for(int i=a; i<=(n); ++i) #define FORD(i, a, n) for(int i=a; i>=(n); --i) struct pot { int hit, hp, nr; }; bool comparison_p( pot A, pot B ) { return ( A.hit <= B.hit ); } bool comparison_n( pot A, pot B ) { if( A.hit > B.hit ) return true; else if( A.hit < B.hit ) return false; else return ( A.hp > B.hp ); } int main() { int n, z, d, a, k = 0, m = 0, dif; cin >> n >> z; pot positive[n]; pot negative[n]; REP( i, n ) { cin >> d >> a; dif = a - d; if( dif >= 0 ) { positive[k].hit = d; positive[k].hp = a; positive[k].nr = i + 1; k++; } else { negative[m].hit = d; negative[m].hp = a; negative[m].nr = i + 1; m++; } } sort( positive, positive+k, comparison_p ); sort( negative, negative+m, comparison_n ); REP( i, k ) { if( z <= positive[i].hit ) { cout << "NIE" << endl; return 0; } z += positive[i].hp - positive[i].hit; } REP( i, m ) { if( z <= negative[i].hit ) { cout << "NIE" << endl; return 0; } z += negative[i].hp - negative[i].hit; if( z <= 0 ) { cout << "NIE" << endl; return 0; } } cout << "TAK" << endl; REP( i, k ) cout << positive[i].nr << " "; REP( i, m ) cout << negative[i].nr << " "; cout << 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 | #include<iostream> #include<algorithm> using namespace std; typedef long long LL; #define REP(i, n) for(int i=0; i<(n); ++i) #define FOR(i, a, n) for(int i=a; i<=(n); ++i) #define FORD(i, a, n) for(int i=a; i>=(n); --i) struct pot { int hit, hp, nr; }; bool comparison_p( pot A, pot B ) { return ( A.hit <= B.hit ); } bool comparison_n( pot A, pot B ) { if( A.hit > B.hit ) return true; else if( A.hit < B.hit ) return false; else return ( A.hp > B.hp ); } int main() { int n, z, d, a, k = 0, m = 0, dif; cin >> n >> z; pot positive[n]; pot negative[n]; REP( i, n ) { cin >> d >> a; dif = a - d; if( dif >= 0 ) { positive[k].hit = d; positive[k].hp = a; positive[k].nr = i + 1; k++; } else { negative[m].hit = d; negative[m].hp = a; negative[m].nr = i + 1; m++; } } sort( positive, positive+k, comparison_p ); sort( negative, negative+m, comparison_n ); REP( i, k ) { if( z <= positive[i].hit ) { cout << "NIE" << endl; return 0; } z += positive[i].hp - positive[i].hit; } REP( i, m ) { if( z <= negative[i].hit ) { cout << "NIE" << endl; return 0; } z += negative[i].hp - negative[i].hit; if( z <= 0 ) { cout << "NIE" << endl; return 0; } } cout << "TAK" << endl; REP( i, k ) cout << positive[i].nr << " "; REP( i, m ) cout << negative[i].nr << " "; cout << endl; return 0; } |