首先明显会想到贪心
对于那些怪物回血比耗血多的,我们显然应该先打耗血少的
那些回血比耗血多的怎么办呢?由于不管怎么打(假设体力负数了还能打),最终体力是一定,
我们从最终体力倒推,相当于先吃药掉血,打怪物回血,这样就转变为第一种情况了
显然我们因先打带的药回血少的,即从正序想,我们因先打所带药物回血多的怪物
type node=record
key,num,loc:longint;
end;
list=array[..] of node;
var a,b:list;
ans:array[..] of longint;
x,y,t,t1,t2,i,n:longint;
m:int64; procedure swap(var a,b:node);
var c:node;
begin
c:=a;
a:=b;
b:=c;
end; procedure qsort(var a:list;m:longint);
procedure sort(l,r: longint);
var i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div ].key;
repeat
while a[i].key<x do inc(i);
while x<a[j].key do dec(j);
if not(i>j) then
begin
swap(a[i],a[j]);
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; begin
sort(,m);
end; begin
readln(n,m);
for i:= to n do
begin
readln(x,y);
if x<=y then
begin
inc(t1);
a[t1].key:=x;
a[t1].num:=y;
a[t1].loc:=i;
end
else begin
inc(t2);
b[t2].key:=y;
b[t2].num:=x;
b[t2].loc:=i;
end;
end;
qsort(a,t1);
for i:= to t1 do
if a[i].key>=m then
begin
writeln('NIE');
halt;
end
else begin
m:=m-a[i].key+a[i].num;
inc(t);
ans[t]:=a[i].loc;
end;
qsort(b,t2);
for i:=t2 downto do
if b[i].num>=m then
begin
writeln('NIE');
halt;
end
else begin
inc(t);
ans[t]:=b[i].loc;
m:=m-b[i].num+b[i].key;
end;
writeln('TAK');
for i:= to t do
write(ans[i],' ');
writeln;
end.