#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
struct pot{
int cena,hp,nr;
pot(int cena,int hp,int nr):cena(cena),hp(hp),nr(nr){};
};
bool s1(pot A,pot B){
if(A.cena<B.cena)return true;
return false;
}
bool s2(pot A,pot B){
if(A.hp>B.hp)return true;
if(A.hp==B.hp)return A.cena>B.cena;
return false;
}
int main(){
int n,hp;
scanf("%d%d",&n,&hp);
vector<pot> A,B;//A-plus,B-minus;
for(int i=1;i<=n;i++){
int a,b;
scanf("%d%d",&a,&b);
if((a-b)>0)B.push_back(pot(a,b,i));
else A.push_back(pot(a,b,i));
}
sort(A.begin(),A.end(),s1);
sort(B.begin(),B.end(),s2);
bool x=true;
for(int i=0;i<A.size();i++){
if(A[i].cena<hp)hp+=(A[i].hp-A[i].cena);
else x=false;
}
if(!x){printf("NIE\n");return 0;}
if(B.size()==0){
printf("TAK\n");
for(int i=0;i<A.size();i++)printf("%d ",A[i].nr);
printf("\n");
return 0;
}
int m=B[0].cena;
for(int i=1;i<B.size();i++)m+=(B[i].cena-B[i-1].hp);
if(hp>m){
printf("TAK\n");
for(int i=0;i<A.size();i++)printf("%d ",A[i].nr);
for(int j=0;j<B.size();j++)printf("%d ",B[j].nr);
printf("\n");
}
else printf("NIE\n");
}
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 | #include<cstdio> #include<algorithm> #include<vector> using namespace std; struct pot{ int cena,hp,nr; pot(int cena,int hp,int nr):cena(cena),hp(hp),nr(nr){}; }; bool s1(pot A,pot B){ if(A.cena<B.cena)return true; return false; } bool s2(pot A,pot B){ if(A.hp>B.hp)return true; if(A.hp==B.hp)return A.cena>B.cena; return false; } int main(){ int n,hp; scanf("%d%d",&n,&hp); vector<pot> A,B;//A-plus,B-minus; for(int i=1;i<=n;i++){ int a,b; scanf("%d%d",&a,&b); if((a-b)>0)B.push_back(pot(a,b,i)); else A.push_back(pot(a,b,i)); } sort(A.begin(),A.end(),s1); sort(B.begin(),B.end(),s2); bool x=true; for(int i=0;i<A.size();i++){ if(A[i].cena<hp)hp+=(A[i].hp-A[i].cena); else x=false; } if(!x){printf("NIE\n");return 0;} if(B.size()==0){ printf("TAK\n"); for(int i=0;i<A.size();i++)printf("%d ",A[i].nr); printf("\n"); return 0; } int m=B[0].cena; for(int i=1;i<B.size();i++)m+=(B[i].cena-B[i-1].hp); if(hp>m){ printf("TAK\n"); for(int i=0;i<A.size();i++)printf("%d ",A[i].nr); for(int j=0;j<B.size();j++)printf("%d ",B[j].nr); printf("\n"); } else printf("NIE\n"); } |
English