#include <cstdio>
#include <algorithm>
#include <vector>
#include<iostream>
#define fru(j,n) for(int j=0;j<n;++j)
#define tr(it,x) for(typeof(x.begin())it=x.begin();it!=x.end();++it)
#define x first
#define y second
using namespace std;
typedef pair<int,int> pii;
typedef long long LL;
const int MAXN = 100005;
pii M[MAXN];
pii t[MAXN];
void solve()
{
int n,z;
scanf("%d%d",&n,&z);
LL zz=z;
fru(i,n)
{
scanf("%d%d",&M[i].x,&M[i].y);
if(M[i].x-M[i].y>0)t[i]=pii(1000000-M[i].x,i);
else t[i]=pii(-1000000+M[i].x,i);
}
sort(t,t+n);
//printf("%lld\n",zz);
bool ok=true;
fru(i,n)
{
zz-=M[t[i].y].x;
if(zz<=0)ok=false;
//printf("%lld\n",zz);
zz+=M[t[i].y].y;
}
if(ok)
{
puts("TAK");
fru(i,n)printf("%d ",t[i].y+1);puts("");
}
else puts("NIE");
}
int main()
{
solve();
return 0;
}
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 | #include <cstdio> #include <algorithm> #include <vector> #include<iostream> #define fru(j,n) for(int j=0;j<n;++j) #define tr(it,x) for(typeof(x.begin())it=x.begin();it!=x.end();++it) #define x first #define y second using namespace std; typedef pair<int,int> pii; typedef long long LL; const int MAXN = 100005; pii M[MAXN]; pii t[MAXN]; void solve() { int n,z; scanf("%d%d",&n,&z); LL zz=z; fru(i,n) { scanf("%d%d",&M[i].x,&M[i].y); if(M[i].x-M[i].y>0)t[i]=pii(1000000-M[i].x,i); else t[i]=pii(-1000000+M[i].x,i); } sort(t,t+n); //printf("%lld\n",zz); bool ok=true; fru(i,n) { zz-=M[t[i].y].x; if(zz<=0)ok=false; //printf("%lld\n",zz); zz+=M[t[i].y].y; } if(ok) { puts("TAK"); fru(i,n)printf("%d ",t[i].y+1);puts(""); } else puts("NIE"); } int main() { solve(); return 0; } |
English