/* Piotr Nosek PA 2014 */ #include <iostream> #include <cstdio> #include <algorithm> #define MAXN 100000 using namespace std; struct monster { int d, a, nr; monster() {}; monster(int _d, int _a, int _nr) { d = _d; a = _a; nr = _nr; } }; bool operator<(const monster &A, const monster &B) { return min(-A.d, -A.d+A.a-B.d) > min(-B.d, -B.d+B.a-A.d); } int n, z; monster arr[MAXN+7]; void read() { scanf("%d %d", &n, &z); int d, a; for(int i=0; i<n; i++) { scanf("%d %d", &d, &a); arr[i] = monster(d, a, i+1); } } void solve() { sort(arr, arr+n); int health = z; for(int i=0; i<n; i++) { health -= arr[i].d; if(health <= 0) //you are dead { printf("NIE"); return; } health += arr[i].a; } printf("TAK\n"); for(int i=0; i<n; i++) printf("%d ", arr[i].nr); } int main() { read(); solve(); 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 | /* Piotr Nosek PA 2014 */ #include <iostream> #include <cstdio> #include <algorithm> #define MAXN 100000 using namespace std; struct monster { int d, a, nr; monster() {}; monster(int _d, int _a, int _nr) { d = _d; a = _a; nr = _nr; } }; bool operator<(const monster &A, const monster &B) { return min(-A.d, -A.d+A.a-B.d) > min(-B.d, -B.d+B.a-A.d); } int n, z; monster arr[MAXN+7]; void read() { scanf("%d %d", &n, &z); int d, a; for(int i=0; i<n; i++) { scanf("%d %d", &d, &a); arr[i] = monster(d, a, i+1); } } void solve() { sort(arr, arr+n); int health = z; for(int i=0; i<n; i++) { health -= arr[i].d; if(health <= 0) //you are dead { printf("NIE"); return; } health += arr[i].a; } printf("TAK\n"); for(int i=0; i<n; i++) printf("%d ", arr[i].nr); } int main() { read(); solve(); return 0; } |