#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, pair<int, int> > dane;
const int N_MAX = 100000;
vector<dane> v;
bool compare(const dane& a, const dane& b) {
int d1 = a.second.first;
int a1 = a.second.second;
int roz1 = a1 - d1;
int d2 = b.second.first;
int a2 = b.second.second;
int roz2 = a2 - d2;
if (roz1 * roz2 <= 0) {
return roz1 > roz2;
} else {
if (roz1 > 0 && roz2 > 0) {
return d1 < d2;
} else {
return a1 > a2;
}
}
}
int main() {
int n;
long long int zycie;
scanf("%d %lld\n", &n ,&zycie);
for (int i = 0; i < n; ++i) {
int d, a;
scanf("%d %d\n", &d, &a);
v.push_back(make_pair(i, make_pair(d, a)));
}
sort(v.begin(), v.end(), compare);
bool result = true;
for (int i = 0; i < n; ++i) {
zycie -= (long long int) v[i].second.first;
if (zycie <= 0) {
result = false;
break;
}
zycie += (long long int) v[i].second.second;
}
if (result) {
printf("TAK\n");
for (int i = 0; i < n-1; ++i) printf("%d ", v[i].first + 1);
printf("%d\n", v[n-1].first + 1);
} else {
printf("NIE\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 55 56 57 58 59 60 61 62 63 | #include <cstdio> #include <cstdlib> #include <vector> #include <algorithm> using namespace std; typedef pair<int, pair<int, int> > dane; const int N_MAX = 100000; vector<dane> v; bool compare(const dane& a, const dane& b) { int d1 = a.second.first; int a1 = a.second.second; int roz1 = a1 - d1; int d2 = b.second.first; int a2 = b.second.second; int roz2 = a2 - d2; if (roz1 * roz2 <= 0) { return roz1 > roz2; } else { if (roz1 > 0 && roz2 > 0) { return d1 < d2; } else { return a1 > a2; } } } int main() { int n; long long int zycie; scanf("%d %lld\n", &n ,&zycie); for (int i = 0; i < n; ++i) { int d, a; scanf("%d %d\n", &d, &a); v.push_back(make_pair(i, make_pair(d, a))); } sort(v.begin(), v.end(), compare); bool result = true; for (int i = 0; i < n; ++i) { zycie -= (long long int) v[i].second.first; if (zycie <= 0) { result = false; break; } zycie += (long long int) v[i].second.second; } if (result) { printf("TAK\n"); for (int i = 0; i < n-1; ++i) printf("%d ", v[i].first + 1); printf("%d\n", v[n-1].first + 1); } else { printf("NIE\n"); } return 0; } |
English