#include <iostream>
#include <algorithm>
typedef struct {int i;int d;int a;} A;
A tab[100001];
bool cmp(const A &a,const A &b)
{
bool s1 = a.d <= a.a;
bool s2 = b.d <= b.a;
if(s1 && s2)
return a.d < b.d;
if(!s1 && !s2)
return a.d > b.d;
return s1;
}
bool test(int n,long long int z)
{
for(int i=0;i<n;i++)
{
if(z <= tab[i].d)
return false;
z += tab[i].a - tab[i].d;
}
return true;
}
int main()
{
int n;
int z;
std::cin.sync_with_stdio(false);
std::cin >> n >> z;
for(int i=0;i<n;i++)
{
tab[i].i = i;
std::cin >> tab[i].d >> tab[i].a;
}
std::sort(tab,tab+n,cmp);
if(test(n,z))
{
std::cout << "TAK" << std::endl;
for(int i=0;i<n;i++)
std::cout << (tab[i].i+1) << " ";
}
else
std::cout << "NIE" << std::endl;
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 | #include <iostream> #include <algorithm> typedef struct {int i;int d;int a;} A; A tab[100001]; bool cmp(const A &a,const A &b) { bool s1 = a.d <= a.a; bool s2 = b.d <= b.a; if(s1 && s2) return a.d < b.d; if(!s1 && !s2) return a.d > b.d; return s1; } bool test(int n,long long int z) { for(int i=0;i<n;i++) { if(z <= tab[i].d) return false; z += tab[i].a - tab[i].d; } return true; } int main() { int n; int z; std::cin.sync_with_stdio(false); std::cin >> n >> z; for(int i=0;i<n;i++) { tab[i].i = i; std::cin >> tab[i].d >> tab[i].a; } std::sort(tab,tab+n,cmp); if(test(n,z)) { std::cout << "TAK" << std::endl; for(int i=0;i<n;i++) std::cout << (tab[i].i+1) << " "; } else std::cout << "NIE" << std::endl; return 0; } |
English