#include<iostream> #include<algorithm> #include<vector> using namespace std; #define ll long long #define ld long double #define vi vector<int> #define pb push_back #define pii pair<int,int> #define mp make_pair #define st first #define nd second #define mini(a,b) a=min(a,(b)) #define maxi(a,b) a=max(a,(b)) #define RE(i,n) for(int i=0,_n=(n);i<_n;++i) #define RI(i,n) for(int i=1,_n=(n);i<=_n;++i) const int inf=1e9+5, nax=1e5+5; int n; ll hp, a, b; vector<pair<pair<ll, ll>, int> > fajne, slabe; int main() { ios_base::sync_with_stdio(0); cin >> n; cin >> hp; RI(i, n) { cin >> a >> b; if(a <= b) fajne.pb(mp(mp(a,b), i)); else slabe.pb(mp(mp(b,a), i)); } sort(fajne.begin(), fajne.end()); sort(slabe.begin(), slabe.end()); reverse(slabe.begin(), slabe.end()); vi RES; RE(i, fajne.size()) { if(fajne[i].st.st >= hp) { cout << "NIE"; return 0; } RES.pb(fajne[i].nd); hp += fajne[i].st.nd - fajne[i].st.st; } RE(i, slabe.size()) { if(slabe[i].st.nd >= hp) { cout << "NIE"; return 0; } RES.pb(slabe[i].nd); hp += slabe[i].st.st - slabe[i].st.nd; } cout << "TAK\n"; RE(i, RES.size()) cout << RES[i] << " "; 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 | #include<iostream> #include<algorithm> #include<vector> using namespace std; #define ll long long #define ld long double #define vi vector<int> #define pb push_back #define pii pair<int,int> #define mp make_pair #define st first #define nd second #define mini(a,b) a=min(a,(b)) #define maxi(a,b) a=max(a,(b)) #define RE(i,n) for(int i=0,_n=(n);i<_n;++i) #define RI(i,n) for(int i=1,_n=(n);i<=_n;++i) const int inf=1e9+5, nax=1e5+5; int n; ll hp, a, b; vector<pair<pair<ll, ll>, int> > fajne, slabe; int main() { ios_base::sync_with_stdio(0); cin >> n; cin >> hp; RI(i, n) { cin >> a >> b; if(a <= b) fajne.pb(mp(mp(a,b), i)); else slabe.pb(mp(mp(b,a), i)); } sort(fajne.begin(), fajne.end()); sort(slabe.begin(), slabe.end()); reverse(slabe.begin(), slabe.end()); vi RES; RE(i, fajne.size()) { if(fajne[i].st.st >= hp) { cout << "NIE"; return 0; } RES.pb(fajne[i].nd); hp += fajne[i].st.nd - fajne[i].st.st; } RE(i, slabe.size()) { if(slabe[i].st.nd >= hp) { cout << "NIE"; return 0; } RES.pb(slabe[i].nd); hp += slabe[i].st.st - slabe[i].st.nd; } cout << "TAK\n"; RE(i, RES.size()) cout << RES[i] << " "; return 0; } |