#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
long long hp;
pair <long long,long long> pot[100007];
int dos[100007];
bool op(int a, int b)
{
if (min(-pot[a].first, -pot[a].first+pot[a].second-pot[b].first)==min(-pot[b].first, -pot[b].first+pot[b].second-pot[a].first))
return a<b;
return min(-pot[a].first, -pot[a].first+pot[a].second-pot[b].first)>min(-pot[b].first, -pot[b].first+pot[b].second-pot[a].first);
}
int main()
{
scanf("%d%lld", &n, &hp);
for (int i=1; i<=n; i++)
{
dos[i]=i;
scanf("%lld%lld", &pot[i].first, &pot[i].second);
}
sort(dos+1, dos+n+1, op);
for (int i=1; i<=n; i++)
{
hp-=pot[dos[i]].first;
if (hp<=0)
{
printf("NIE");
return 0;
}
hp+=pot[dos[i]].second;
}
printf("TAK\n");
for (int i=1; i<=n; i++)
printf("%d ", dos[i]);
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 | #include <iostream> #include <cstdio> #include <algorithm> using namespace std; int n; long long hp; pair <long long,long long> pot[100007]; int dos[100007]; bool op(int a, int b) { if (min(-pot[a].first, -pot[a].first+pot[a].second-pot[b].first)==min(-pot[b].first, -pot[b].first+pot[b].second-pot[a].first)) return a<b; return min(-pot[a].first, -pot[a].first+pot[a].second-pot[b].first)>min(-pot[b].first, -pot[b].first+pot[b].second-pot[a].first); } int main() { scanf("%d%lld", &n, &hp); for (int i=1; i<=n; i++) { dos[i]=i; scanf("%lld%lld", &pot[i].first, &pot[i].second); } sort(dos+1, dos+n+1, op); for (int i=1; i<=n; i++) { hp-=pot[dos[i]].first; if (hp<=0) { printf("NIE"); return 0; } hp+=pot[dos[i]].second; } printf("TAK\n"); for (int i=1; i<=n; i++) printf("%d ", dos[i]); return 0; } |
English