Link
同上一题。
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=100007;
int read(){int x;scanf("%d",&x);return x;}
struct node{int x,y,id;}a[N],b[N];
int f[N],x[N],y[N];
int cmp1(node x,node y){return x.x<y.x;}
int cmp2(node x,node y){return x.y>y.y;}
int main()
{
int n=read(),i,c1=0,c2=0;LL s=read();
for(i=1;i<=n;++i)
{
x[i]=read(),y[i]=read();
if(x[i]<=y[i]) a[++c1]=(node){x[i],y[i],i};
else b[++c2]=(node){x[i],y[i],i};
}
sort(a+1,a+c1+1,cmp1),sort(b+1,b+c2+1,cmp2);
for(i=1;i<=c1;++i) f[i]=a[i].id;
for(i=1;i<=c2;++i) f[c1+i]=b[i].id;
for(i=1;i<=n;++i)
{
s-=x[f[i]];
if(s<=0) return !printf("NIE");
s+=y[f[i]];
}
puts("TAK");
for(i=1;i<=n;++i) printf("%d ",f[i]);
}