#include <cstdio>
#include <algorithm>
using namespace std;
struct Trzy
{
int d, a, ind;
Trzy(){}
};
Trzy tab[100000];
bool operator<(Trzy x, Trzy y)
{
if(x.a-x.d >= 0)
{
if(y.a-y.d < 0)
return 1;
return x.d < y.d;
}
if(y.a-y.d >= 0)
return 0;
return x.a > y.a;
}
int main()
{
int n;
long long z;
scanf("%d%lld", &n, &z);
for(int i=0; i < n; i++)
{
scanf("%d%d", &tab[i].d, &tab[i].a);
tab[i].ind = i+1;
}
sort(tab, tab+n);
int i=0;
while(i < n && z - tab[i].d > 0)
{
z = z - tab[i].d + tab[i].a;
i++;
}
if(i < n)
printf("NIE\n");
else
{
printf("TAK\n");
for(int i=0; i < n; i++)
printf("%d ", tab[i].ind);
}
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 50 51 52 53 54 55 56 57 | #include <cstdio> #include <algorithm> using namespace std; struct Trzy { int d, a, ind; Trzy(){} }; Trzy tab[100000]; bool operator<(Trzy x, Trzy y) { if(x.a-x.d >= 0) { if(y.a-y.d < 0) return 1; return x.d < y.d; } if(y.a-y.d >= 0) return 0; return x.a > y.a; } int main() { int n; long long z; scanf("%d%lld", &n, &z); for(int i=0; i < n; i++) { scanf("%d%d", &tab[i].d, &tab[i].a); tab[i].ind = i+1; } sort(tab, tab+n); int i=0; while(i < n && z - tab[i].d > 0) { z = z - tab[i].d + tab[i].a; i++; } if(i < n) printf("NIE\n"); else { printf("TAK\n"); for(int i=0; i < n; i++) printf("%d ", tab[i].ind); } return 0; } |
English