#include <vector> #include <algorithm> #include <cstdio> #include <set> #include <queue> #include <map> using namespace std; #define ref & #define st first #define nd second #define mp make_pair #define pb push_back #define POKA(x) cerr << #x << " = " << x << endl; typedef pair<int,int> pii; typedef vector<int> vi; //////////////////////////////////////////////////////////////////////////////// int main(){ int n; long long z; scanf("%d", &n); scanf("%lld", &z); vi d(n), a(n); vector<pii> lewe, prawe, srodkowe; for(int i = 0; i < n; ++i){ scanf("%d%d", &d[i], &a[i]); if(d[i] < a[i]) lewe.pb(pii(d[i],i)); else if(d[i] == a[i]) srodkowe.pb(pii(0,i)); else prawe.pb(pii(a[i],i)); } sort(lewe.begin(), lewe.end()); sort(prawe.begin(), prawe.end(), greater<pii>()); lewe.insert(lewe.end(), srodkowe.begin(), srodkowe.end()); lewe.insert(lewe.end(), prawe.begin(), prawe.end()); bool fail = 0; for(int i = 0; i < n; ++i){ int x = lewe[i].nd; z -= d[x]; if(z <= 0) { fail = 1; break; } z += a[x]; } if(fail) puts("NIE"); else{ puts("TAK"); for(int i = 0; i < n; ++i) printf("%d ", lewe[i].nd + 1); puts(""); } 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 | #include <vector> #include <algorithm> #include <cstdio> #include <set> #include <queue> #include <map> using namespace std; #define ref & #define st first #define nd second #define mp make_pair #define pb push_back #define POKA(x) cerr << #x << " = " << x << endl; typedef pair<int,int> pii; typedef vector<int> vi; //////////////////////////////////////////////////////////////////////////////// int main(){ int n; long long z; scanf("%d", &n); scanf("%lld", &z); vi d(n), a(n); vector<pii> lewe, prawe, srodkowe; for(int i = 0; i < n; ++i){ scanf("%d%d", &d[i], &a[i]); if(d[i] < a[i]) lewe.pb(pii(d[i],i)); else if(d[i] == a[i]) srodkowe.pb(pii(0,i)); else prawe.pb(pii(a[i],i)); } sort(lewe.begin(), lewe.end()); sort(prawe.begin(), prawe.end(), greater<pii>()); lewe.insert(lewe.end(), srodkowe.begin(), srodkowe.end()); lewe.insert(lewe.end(), prawe.begin(), prawe.end()); bool fail = 0; for(int i = 0; i < n; ++i){ int x = lewe[i].nd; z -= d[x]; if(z <= 0) { fail = 1; break; } z += a[x]; } if(fail) puts("NIE"); else{ puts("TAK"); for(int i = 0; i < n; ++i) printf("%d ", lewe[i].nd + 1); puts(""); } return 0; } |