#include <algorithm> #include <iostream> #include <vector> using namespace std; const int nmax = 1e5 + 10; typedef long long ll; vector<int> points_plus, points_minus; ll d[nmax], a[nmax]; bool points_plus_cmp(const int lhs, const int rhs) { return d[lhs] < d[rhs]; } bool points_minus_cmp(const int lhs, const int rhs) { if (a[lhs] != a[rhs]) return a[lhs] > a[rhs]; return d[lhs] > d[rhs]; } int main() { ios_base::sync_with_stdio(false); int n; ll z; cin >> n >> z; for (int i = 1; i <= n; i++) { cin >> d[i] >> a[i]; ll diff = a[i] - d[i]; if (diff >= 0) { points_plus.push_back(i); } else { points_minus.push_back(i); } } bool correct = true; sort(points_plus.begin(), points_plus.end(), points_plus_cmp); for (auto m : points_plus) { if (d[m] >= z) correct = false; z += a[m] - d[m]; } // cerr << z << ' ' << correct << endl; sort(points_minus.begin(), points_minus.end(), points_minus_cmp); for (auto m : points_minus) { if (d[m] >= z) correct = false; z += a[m] - d[m]; } // cerr << z << ' ' << correct << endl; if (correct && (z > 0)) { cout << "TAK\n"; for (auto m : points_plus) { cout << m<< ' '; } for (auto m : points_minus) { cout << m << ' '; } cout << '\n'; } else { cout << "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 64 65 66 67 | #include <algorithm> #include <iostream> #include <vector> using namespace std; const int nmax = 1e5 + 10; typedef long long ll; vector<int> points_plus, points_minus; ll d[nmax], a[nmax]; bool points_plus_cmp(const int lhs, const int rhs) { return d[lhs] < d[rhs]; } bool points_minus_cmp(const int lhs, const int rhs) { if (a[lhs] != a[rhs]) return a[lhs] > a[rhs]; return d[lhs] > d[rhs]; } int main() { ios_base::sync_with_stdio(false); int n; ll z; cin >> n >> z; for (int i = 1; i <= n; i++) { cin >> d[i] >> a[i]; ll diff = a[i] - d[i]; if (diff >= 0) { points_plus.push_back(i); } else { points_minus.push_back(i); } } bool correct = true; sort(points_plus.begin(), points_plus.end(), points_plus_cmp); for (auto m : points_plus) { if (d[m] >= z) correct = false; z += a[m] - d[m]; } // cerr << z << ' ' << correct << endl; sort(points_minus.begin(), points_minus.end(), points_minus_cmp); for (auto m : points_minus) { if (d[m] >= z) correct = false; z += a[m] - d[m]; } // cerr << z << ' ' << correct << endl; if (correct && (z > 0)) { cout << "TAK\n"; for (auto m : points_plus) { cout << m<< ' '; } for (auto m : points_minus) { cout << m << ' '; } cout << '\n'; } else { cout << "NIE\n"; } return 0; } |