#include <iostream> #include <algorithm> #include <vector> #include <list> using namespace std; typedef long double ld; typedef long long ll; typedef pair<ll, ll> para; typedef pair<ll, para> potwor; const int MAX_N = 100009; const ll INF = 2000000009; vector <int> poczatek; vector <potwor> P; vector <int> koniec; int main(){ ll n, z; cin >> n >> z; ll dodaj=0, odejmij=0; ll minpot=INF; /// minimalny potion for(int i=1; i<=n; i++){ ll d, a; cin >> d >> a; dodaj+=a; odejmij+=d; minpot=min(minpot, a); if(d<=a && d<z){ poczatek.push_back(i); }else{ potwor A; A.first=a; A.second.first=d-a; A.second.second = i; P.push_back(A); } } z=z-odejmij+dodaj; bool czy=false; if((z)<=minpot){ cout << "NIE" << endl; }else if(z<=0){ cout << "NIE" << endl; } else{ czy=true; sort(P.begin(), P.end()); for(int i=0; i<P.size(); i++){ if(P[i].first<z){ z+=P[i].second.first; koniec.push_back(P[i].second.second); }else{czy=false;} } if(czy==true){ cout << "TAK" << endl; for(int i=0; i<poczatek.size(); i++){ cout << poczatek[i] << " "; } reverse(koniec.begin(), koniec.end()); for(int i=0; i<koniec.size(); i++){ cout << koniec[i] << " "; } }else{cout << "NIE" << 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include <iostream> #include <algorithm> #include <vector> #include <list> using namespace std; typedef long double ld; typedef long long ll; typedef pair<ll, ll> para; typedef pair<ll, para> potwor; const int MAX_N = 100009; const ll INF = 2000000009; vector <int> poczatek; vector <potwor> P; vector <int> koniec; int main(){ ll n, z; cin >> n >> z; ll dodaj=0, odejmij=0; ll minpot=INF; /// minimalny potion for(int i=1; i<=n; i++){ ll d, a; cin >> d >> a; dodaj+=a; odejmij+=d; minpot=min(minpot, a); if(d<=a && d<z){ poczatek.push_back(i); }else{ potwor A; A.first=a; A.second.first=d-a; A.second.second = i; P.push_back(A); } } z=z-odejmij+dodaj; bool czy=false; if((z)<=minpot){ cout << "NIE" << endl; }else if(z<=0){ cout << "NIE" << endl; } else{ czy=true; sort(P.begin(), P.end()); for(int i=0; i<P.size(); i++){ if(P[i].first<z){ z+=P[i].second.first; koniec.push_back(P[i].second.second); }else{czy=false;} } if(czy==true){ cout << "TAK" << endl; for(int i=0; i<poczatek.size(); i++){ cout << poczatek[i] << " "; } reverse(koniec.begin(), koniec.end()); for(int i=0; i<koniec.size(); i++){ cout << koniec[i] << " "; } }else{cout << "NIE" << endl;} } return 0; } |