#include <cstdio> #include <vector> #include <algorithm> #include <functional> #define D first.first #define A first.second #define N second #define scanf(args...) scanf(args) ? : 0 #define all(q) (q).begin(),(q).end() using namespace std; int n; long long z; typedef pair<pair<int,int>,int> T; vector<T> p,m; vector<int> w; bool lol(const vector<T>& v) { for(unsigned i=0;i<v.size();i++) { if(v[i].D<z) { z-=v[i].D; z+=v[i].A; w.push_back(v[i].N); } else return false; } return true; } bool cmp(const T &a, const T &b) { return a.A > b.A; //return a.A-a.D > b.A - b.D; } bool solve() { sort(all(p)); /*for(auto it=p.begin();it!=p.end();it++) printf("%d %d\n",it->D,it->A); printf("\n");*/ sort(all(m),cmp); //for(auto it=m.begin();it!=m.end();it++) // printf("%d %d\n",it->D,it->A); if(!lol(p))return false; if(!lol(m))return false; return true; } int main() { int d,a; scanf("%d%lld",&n,&z); for(int i=0;i<n;i++) { scanf("%d%d",&d,&a); if(a>=d) p.push_back(make_pair(make_pair(d,a),i+1)); else m.push_back(make_pair(make_pair(d,a),i+1)); } if(solve()) { printf("TAK\n"); for(int i=0;i<n;i++) printf("%d ",w[i]); printf("\n"); } else printf("NIE\n"); }
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 | #include <cstdio> #include <vector> #include <algorithm> #include <functional> #define D first.first #define A first.second #define N second #define scanf(args...) scanf(args) ? : 0 #define all(q) (q).begin(),(q).end() using namespace std; int n; long long z; typedef pair<pair<int,int>,int> T; vector<T> p,m; vector<int> w; bool lol(const vector<T>& v) { for(unsigned i=0;i<v.size();i++) { if(v[i].D<z) { z-=v[i].D; z+=v[i].A; w.push_back(v[i].N); } else return false; } return true; } bool cmp(const T &a, const T &b) { return a.A > b.A; //return a.A-a.D > b.A - b.D; } bool solve() { sort(all(p)); /*for(auto it=p.begin();it!=p.end();it++) printf("%d %d\n",it->D,it->A); printf("\n");*/ sort(all(m),cmp); //for(auto it=m.begin();it!=m.end();it++) // printf("%d %d\n",it->D,it->A); if(!lol(p))return false; if(!lol(m))return false; return true; } int main() { int d,a; scanf("%d%lld",&n,&z); for(int i=0;i<n;i++) { scanf("%d%d",&d,&a); if(a>=d) p.push_back(make_pair(make_pair(d,a),i+1)); else m.push_back(make_pair(make_pair(d,a),i+1)); } if(solve()) { printf("TAK\n"); for(int i=0;i<n;i++) printf("%d ",w[i]); printf("\n"); } else printf("NIE\n"); } |