#include <stdio.h> #include <set> #include <algorithm> #include <iostream> using namespace std; typedef set<pair<long long,pair<long long, int> > > set_type; int main() { long long n,z; set_type sm,sp; scanf("%lld%lld",&n,&z); for (int i=0;i<n;i++) { long long d,a; scanf("%lld%lld",&d,&a); if(a>=d) sp.insert(make_pair(d,make_pair(a,i))); else sm.insert(make_pair(-a,make_pair(-d,i))); } bool ret = true; for (set_type::iterator it = sp.begin();it!=sp.end();++it) { z-=it->first; if(z<=0) {ret=false;break;} z+=it->second.first; } for (set_type::iterator it = sm.begin();it!=sm.end() && ret;++it) { z-=-it->second.first; if(z<=0) {ret=false;break;} z+=-it->first; } if (!ret) cout << "NIE" << endl; else { cout << "TAK" << endl; for (set_type::iterator it = sp.begin();it!=sp.end();++it) { cout << it->second.second + 1 << " "; } for (set_type::iterator it = sm.begin();it!=sm.end();++it) { cout << it->second.second + 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 | #include <stdio.h> #include <set> #include <algorithm> #include <iostream> using namespace std; typedef set<pair<long long,pair<long long, int> > > set_type; int main() { long long n,z; set_type sm,sp; scanf("%lld%lld",&n,&z); for (int i=0;i<n;i++) { long long d,a; scanf("%lld%lld",&d,&a); if(a>=d) sp.insert(make_pair(d,make_pair(a,i))); else sm.insert(make_pair(-a,make_pair(-d,i))); } bool ret = true; for (set_type::iterator it = sp.begin();it!=sp.end();++it) { z-=it->first; if(z<=0) {ret=false;break;} z+=it->second.first; } for (set_type::iterator it = sm.begin();it!=sm.end() && ret;++it) { z-=-it->second.first; if(z<=0) {ret=false;break;} z+=-it->first; } if (!ret) cout << "NIE" << endl; else { cout << "TAK" << endl; for (set_type::iterator it = sp.begin();it!=sp.end();++it) { cout << it->second.second + 1 << " "; } for (set_type::iterator it = sm.begin();it!=sm.end();++it) { cout << it->second.second + 1 << " "; } cout << endl; } return 0; } |