#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
struct monsta{
int id;
int dmg;
int live;
float f;
bool operator < (const monsta &x)const
{
return f>x.f;
}
};
bool comp_dmg(const monsta &x, const monsta &xx){
return x.dmg < xx.dmg;
}
int main(){
int d;
int dd;
int x,y ;
monsta mm[100000];
scanf("%d",&d);
scanf("%d",&dd);
int to_eat=0;
for(int i=0;i<d;i++){
scanf("%d",&x);
scanf("%d",&y);
monsta m={i+1,x,y,float(y)/float(x)};
if(m.f<=1.0){
++to_eat;
}
mm[i]=m;
}
sort(mm,mm+d);
sort(mm,mm+to_eat,comp_dmg);
// sort(mm+to_eat,mm+d);
for(int i=0;i<d;i++){
dd-=mm[i].dmg;
if(dd<=0){
// printf("%d\n",i);
puts("NIE");
return 0;
}
dd+=mm[i].live;
}
puts("TAK");
for(int i=0;i<d;i++)
printf("%d ",mm[i].id);
}
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 | #include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> using namespace std; struct monsta{ int id; int dmg; int live; float f; bool operator < (const monsta &x)const { return f>x.f; } }; bool comp_dmg(const monsta &x, const monsta &xx){ return x.dmg < xx.dmg; } int main(){ int d; int dd; int x,y ; monsta mm[100000]; scanf("%d",&d); scanf("%d",&dd); int to_eat=0; for(int i=0;i<d;i++){ scanf("%d",&x); scanf("%d",&y); monsta m={i+1,x,y,float(y)/float(x)}; if(m.f<=1.0){ ++to_eat; } mm[i]=m; } sort(mm,mm+d); sort(mm,mm+to_eat,comp_dmg); // sort(mm+to_eat,mm+d); for(int i=0;i<d;i++){ dd-=mm[i].dmg; if(dd<=0){ // printf("%d\n",i); puts("NIE"); return 0; } dd+=mm[i].live; } puts("TAK"); for(int i=0;i<d;i++) printf("%d ",mm[i].id); } |
English