#include <iostream> #include <stdio.h> #include <vector> #include <algorithm> #include <string> #include <list> using namespace std; const int SIZE = 100000; int p[SIZE]; int t[SIZE]; int d[SIZE]; int c[SIZE]; int r[SIZE]; bool cmp(int a, int b) { if (t[a] != t[b]) return t[a] < t[b]; if (t[a] == -1) return d[a] < d[b]; return c[a] > c[b]; } int main() { int n, i, debit, credit; long long z; cin >> n >> z; for (i=0; i<n; i++) { cin >> debit >> credit; p[i] = i; d[i] = debit; c[i] = credit; if (debit < credit) t[i] = -1; else if (debit == credit) t[i] = 0; else t[i] = 1; } sort(p, p + n, cmp); for (i=0; i<n; i++) { z -= d[p[i]]; if (z <= 0) { cout << "NIE" << endl; return(0); } z += c[p[i]]; } cout << "TAK" << endl; cout << p[0]+1; for (i=1; i<n; i++) cout << " " << p[i]+1; 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 | #include <iostream> #include <stdio.h> #include <vector> #include <algorithm> #include <string> #include <list> using namespace std; const int SIZE = 100000; int p[SIZE]; int t[SIZE]; int d[SIZE]; int c[SIZE]; int r[SIZE]; bool cmp(int a, int b) { if (t[a] != t[b]) return t[a] < t[b]; if (t[a] == -1) return d[a] < d[b]; return c[a] > c[b]; } int main() { int n, i, debit, credit; long long z; cin >> n >> z; for (i=0; i<n; i++) { cin >> debit >> credit; p[i] = i; d[i] = debit; c[i] = credit; if (debit < credit) t[i] = -1; else if (debit == credit) t[i] = 0; else t[i] = 1; } sort(p, p + n, cmp); for (i=0; i<n; i++) { z -= d[p[i]]; if (z <= 0) { cout << "NIE" << endl; return(0); } z += c[p[i]]; } cout << "TAK" << endl; cout << p[0]+1; for (i=1; i<n; i++) cout << " " << p[i]+1; cout << endl; return(0); } |