#include <cstdio>
#include <algorithm>
#include <vector>
typedef std::pair<long long, std::pair<long long, long> > pll; // (index, (life needed, heal/damage))
int main()
{
long long n, z;
scanf("%lld%lld", &n, &z);
std::vector<pll> plus;
std::vector<pll> minus;
for (int i = 1; i <= n; ++i) {
long long d, a;
scanf("%lld%lld", &d, &a);
pll add = std::make_pair(i, std::make_pair(d, a - d));
if (add.second.second < 0) {
minus.push_back(add);
} else {
plus.push_back(add);
}
}
int pidx = 0, midx = 0;
std::sort(plus.begin(), plus.end(),
[&] (const pll &_lhs, const pll &_rhs) {
return _lhs.second.first < _rhs.second.first;
});
std::sort(minus.begin(), minus.end(),
[&] (const pll &_lhs, const pll &_rhs) {
return (_lhs.second.first > _rhs.second.first) || (_lhs.second.first == _rhs.second.first && _lhs.second.second > _rhs.second.second);
});
while (pidx < plus.size() && plus[pidx].second.first < z) {
z += plus[pidx].second.second;
++pidx;
}
if (pidx != plus.size()) {
printf("NIE\n");
return 0;
}
while (midx < minus.size() && minus[midx].second.first < z) {
z += minus[midx].second.second;
++midx;
}
if (midx != minus.size()) {
printf("NIE\n");
return 0;
}
printf("TAK\n");
for (auto it = plus.begin(); it != plus.end(); ++it) {
printf("%lld ", it->first);
}
for (auto it = minus.begin(); it != minus.end(); ++it) {
printf("%lld ", it->first);
}
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> #include <vector> typedef std::pair<long long, std::pair<long long, long> > pll; // (index, (life needed, heal/damage)) int main() { long long n, z; scanf("%lld%lld", &n, &z); std::vector<pll> plus; std::vector<pll> minus; for (int i = 1; i <= n; ++i) { long long d, a; scanf("%lld%lld", &d, &a); pll add = std::make_pair(i, std::make_pair(d, a - d)); if (add.second.second < 0) { minus.push_back(add); } else { plus.push_back(add); } } int pidx = 0, midx = 0; std::sort(plus.begin(), plus.end(), [&] (const pll &_lhs, const pll &_rhs) { return _lhs.second.first < _rhs.second.first; }); std::sort(minus.begin(), minus.end(), [&] (const pll &_lhs, const pll &_rhs) { return (_lhs.second.first > _rhs.second.first) || (_lhs.second.first == _rhs.second.first && _lhs.second.second > _rhs.second.second); }); while (pidx < plus.size() && plus[pidx].second.first < z) { z += plus[pidx].second.second; ++pidx; } if (pidx != plus.size()) { printf("NIE\n"); return 0; } while (midx < minus.size() && minus[midx].second.first < z) { z += minus[midx].second.second; ++midx; } if (midx != minus.size()) { printf("NIE\n"); return 0; } printf("TAK\n"); for (auto it = plus.begin(); it != plus.end(); ++it) { printf("%lld ", it->first); } for (auto it = minus.begin(); it != minus.end(); ++it) { printf("%lld ", it->first); } return 0; } |
English