#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct pot { int i, d, a; };
vector<pot> p1, p2;
bool cmp1(const pot &p1, const pot &p2)
{
return p1.d < p2.d;
}
bool cmp2(const pot &p1, const pot &p2)
{
int r1 = min(0, p1.a - p2.d) - p1.d;
int r2 = min(0, p2.a - p1.d) - p2.d;
if (r1 != r2) return r1 > r2;
r1 = p1.a - p1.d;
r2 = p2.a - p2.d;
if (r1 != r2) return r1 > r2;
return p1.d > p2.d;
}
int main()
{
int n, z;
scanf("%d%d", &n, &z);
p1.reserve(n);
p2.reserve(n);
for (int i=0; i<n; i++)
{
pot p;
p.i = i;
scanf("%d%d", &p.d, &p.a);
if (p.a - p.d >= 0) p1.push_back(p);
else p2.push_back(p);
}
sort(p1.begin(), p1.end(), cmp1);
sort(p2.begin(), p2.end(), cmp2);
p1.insert(p1.end(), p2.begin(), p2.end());
long long x = z;
for (int i=0; i<n; i++)
{
//printf("%d %d\n", p1[i].d, p1[i].a);
x -= p1[i].d;
if (x <= 0) { printf("NIE\n"); return 0; }
x += p1[i].a;
}
printf("TAK\n");
for (int i=0; i<n; i++) printf("%d ", p1[i].i+1);
printf("\n");
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 | #include<cstdio> #include<vector> #include<algorithm> using namespace std; struct pot { int i, d, a; }; vector<pot> p1, p2; bool cmp1(const pot &p1, const pot &p2) { return p1.d < p2.d; } bool cmp2(const pot &p1, const pot &p2) { int r1 = min(0, p1.a - p2.d) - p1.d; int r2 = min(0, p2.a - p1.d) - p2.d; if (r1 != r2) return r1 > r2; r1 = p1.a - p1.d; r2 = p2.a - p2.d; if (r1 != r2) return r1 > r2; return p1.d > p2.d; } int main() { int n, z; scanf("%d%d", &n, &z); p1.reserve(n); p2.reserve(n); for (int i=0; i<n; i++) { pot p; p.i = i; scanf("%d%d", &p.d, &p.a); if (p.a - p.d >= 0) p1.push_back(p); else p2.push_back(p); } sort(p1.begin(), p1.end(), cmp1); sort(p2.begin(), p2.end(), cmp2); p1.insert(p1.end(), p2.begin(), p2.end()); long long x = z; for (int i=0; i<n; i++) { //printf("%d %d\n", p1[i].d, p1[i].a); x -= p1[i].d; if (x <= 0) { printf("NIE\n"); return 0; } x += p1[i].a; } printf("TAK\n"); for (int i=0; i<n; i++) printf("%d ", p1[i].i+1); printf("\n"); return 0; } |
English