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
#include<cstdio>
#include <algorithm>
int o[100004],p[100004],n[100004],po[100004];
bool s1(int a, int b){return (po[a]>po[b]);} 
bool s2(int a, int b){return (o[a]<o[b]);} 
bool s3(int a, int b){return (p[a]>p[b]);} 

main(){
int lp,pz;
scanf("%d%d",&lp,&pz);
for (int i=1,w,e;i<=lp;i++)scanf("%d%d",o+i,p+i),po[i]=p[i]-o[i],n[i]=i;
std::sort(n+1,n+lp+1,s1);
int z=1;
while(po[n[z]]>=0&&z<=lp)z++;
std::sort(n+1,n+z,s2);
long long s=pz;bool tak=1;
for (int i=1;i<z;i++){if(o[n[i]]>=s){tak=0; break;}s+=po[n[i]];}
int a=z;
if (tak==1&&a<=lp)
{
std::sort(n+a,n+lp+1,s3);
for (int i=a;i<=lp;i++){if(o[n[i]]>=s){tak=0; break;}s+=po[n[i]];}
}
printf(tak?"TAK\n":"NIE\n");
if(tak){for(int i=1;i<=lp;i++)printf("%d ",n[i]);printf("\n");}
}