#include <iostream> #include<algorithm> using namespace std; struct mob{int nr;int sc;int dmg;int pot;}; bool x=0; int n,i,a,b,s; long long int hp; int sgn(int a){ if(a>0) return 1; if(a==0) return 0; return -1; } bool comp(const mob& x,const mob& y) { return x.sc < y.sc; } int main() { ios_base::sync_with_stdio(0); cin>>n>>hp; struct mob z[n]; for(i=0;i<n;i++){ cin>>z[i].dmg>>z[i].pot; z[i].nr=i+1; s=sgn(z[i].pot-z[i].dmg); if(s==1) z[i].sc=z[i].dmg; else if(s==0) z[i].sc=100001; else z[i].sc=200002-z[i].dmg; } sort(z,z+n,comp); for(i=0;i<n;i++){ if(hp<z[i].dmg){x=1; i=n;} else hp+=z[i].pot-z[i].dmg; } if(x) cout<<"NIE"<<endl; else{ cout<<"TAK"<<endl; for(i=0;i<n;i++) cout<<z[i].nr<<" "; } 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 | #include <iostream> #include<algorithm> using namespace std; struct mob{int nr;int sc;int dmg;int pot;}; bool x=0; int n,i,a,b,s; long long int hp; int sgn(int a){ if(a>0) return 1; if(a==0) return 0; return -1; } bool comp(const mob& x,const mob& y) { return x.sc < y.sc; } int main() { ios_base::sync_with_stdio(0); cin>>n>>hp; struct mob z[n]; for(i=0;i<n;i++){ cin>>z[i].dmg>>z[i].pot; z[i].nr=i+1; s=sgn(z[i].pot-z[i].dmg); if(s==1) z[i].sc=z[i].dmg; else if(s==0) z[i].sc=100001; else z[i].sc=200002-z[i].dmg; } sort(z,z+n,comp); for(i=0;i<n;i++){ if(hp<z[i].dmg){x=1; i=n;} else hp+=z[i].pot-z[i].dmg; } if(x) cout<<"NIE"<<endl; else{ cout<<"TAK"<<endl; for(i=0;i<n;i++) cout<<z[i].nr<<" "; } return 0; } |