#include<cstdio> #include<iostream> #include<algorithm> #include<queue> using namespace std; vector<pair<pair<long long int,long long int>, long long int > > dod; vector<pair<pair<long long int,long long int>, long long int > > uj; int main() { ios_base::sync_with_stdio(0); long long int n, leben, ok, x, a, b; cin >> n >> leben; for(int i=1; i<=n; i++) { cin >> a >> b; if(b>=a) dod.push_back(make_pair(make_pair(a,b),i)); else uj.push_back(make_pair(make_pair(b,a),i)); } sort(dod.begin(), dod.end()); sort(uj.begin(), uj.end()); ok=5; for(int i=0; i<dod.size(); i++) { a=dod[i].first.first; b=dod[i].first.second; x=dod[i].second; leben=leben-a; if(leben<=0) ok=0; leben=leben+b; } for(int i=uj.size()-1; i>=0; i--) { b=uj[i].first.first; a=uj[i].first.second; x=uj[i].second; leben=leben-a; if(leben<=0) ok=0; leben=leben+b; } if(ok==5) { cout << "TAK\n"; for(int i=0; i<dod.size(); i++) { x=dod[i].second; cout << x << " "; } for(int i=uj.size()-1; i>=0; i--) { x=uj[i].second; cout << x << " "; } } else cout << "NIE\n"; 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 64 65 | #include<cstdio> #include<iostream> #include<algorithm> #include<queue> using namespace std; vector<pair<pair<long long int,long long int>, long long int > > dod; vector<pair<pair<long long int,long long int>, long long int > > uj; int main() { ios_base::sync_with_stdio(0); long long int n, leben, ok, x, a, b; cin >> n >> leben; for(int i=1; i<=n; i++) { cin >> a >> b; if(b>=a) dod.push_back(make_pair(make_pair(a,b),i)); else uj.push_back(make_pair(make_pair(b,a),i)); } sort(dod.begin(), dod.end()); sort(uj.begin(), uj.end()); ok=5; for(int i=0; i<dod.size(); i++) { a=dod[i].first.first; b=dod[i].first.second; x=dod[i].second; leben=leben-a; if(leben<=0) ok=0; leben=leben+b; } for(int i=uj.size()-1; i>=0; i--) { b=uj[i].first.first; a=uj[i].first.second; x=uj[i].second; leben=leben-a; if(leben<=0) ok=0; leben=leben+b; } if(ok==5) { cout << "TAK\n"; for(int i=0; i<dod.size(); i++) { x=dod[i].second; cout << x << " "; } for(int i=uj.size()-1; i>=0; i--) { x=uj[i].second; cout << x << " "; } } else cout << "NIE\n"; return 0; } |