#include <algorithm>
#include <iostream>
#include <vector>
struct monster
{
int n, d, a;
};
bool operator<(const monster& a, const monster& b)
{
if( a.a >= a.d && b.a >= b.d ) {
return a.d < b.d;
}
if( a.a < a.d && b.a < b.d ) {
return a.a > b.a;
}
return (a.a-a.d) > (b.a-b.d);
}
int main()
{
std::cin.sync_with_stdio(false);
std::cout.sync_with_stdio(false);
int n;
long long int z;
std::cin >> n >> z;
std::vector<monster> m(n);
for(int i = 0; i < n; ++i ) {
int a, d;
std::cin >> d >> a;
m[i].n = i+1;
m[i].d = d;
m[i].a = a;
}
std::sort(m.begin(), m.end());
bool survived = true;
for(const monster& i : m) {
if( z <= i.d ) {
survived = false;
break;
}
z += i.a - i.d;
}
if( survived ) {
std::cout << "TAK" << std::endl;
for(const monster& i : m) std::cout << i.n << " ";
}
else {
std::cout << "NIE";
}
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 | #include <algorithm> #include <iostream> #include <vector> struct monster { int n, d, a; }; bool operator<(const monster& a, const monster& b) { if( a.a >= a.d && b.a >= b.d ) { return a.d < b.d; } if( a.a < a.d && b.a < b.d ) { return a.a > b.a; } return (a.a-a.d) > (b.a-b.d); } int main() { std::cin.sync_with_stdio(false); std::cout.sync_with_stdio(false); int n; long long int z; std::cin >> n >> z; std::vector<monster> m(n); for(int i = 0; i < n; ++i ) { int a, d; std::cin >> d >> a; m[i].n = i+1; m[i].d = d; m[i].a = a; } std::sort(m.begin(), m.end()); bool survived = true; for(const monster& i : m) { if( z <= i.d ) { survived = false; break; } z += i.a - i.d; } if( survived ) { std::cout << "TAK" << std::endl; for(const monster& i : m) std::cout << i.n << " "; } else { std::cout << "NIE"; } return 0; } |
English