#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
pair<int,int> tab[100001];
pair<int,int> t[100001];
int hp[100001][3], wyn[100001];
int ile = -1, j = -1, licz, n;
long long pocz, z;
bool blad;
int main()
{
scanf("%d", &n);
scanf("%lld", &z);
for( int a = 1; a <= n; a++ )
{
scanf("%d", &hp[a][1]);
scanf("%d", &hp[a][2]);
if( hp[a][1] <= hp[a][2] )
{
tab[++ile].first = hp[a][1];
tab[ile].second = a;
}
else
{
t[++j].first = hp[a][2]+1;
t[j].second = a;
}
}
sort( tab, tab+ile+1 );
sort( t, t+j+1 );
for( int a = 0; a <= ile; a++ )
{
if( tab[a].first < z )
{
wyn[++licz] = tab[a].second;
z += (hp[wyn[licz]][2]-hp[wyn[licz]][1]);
}
else
{
blad = 1;
break;
}
}
for( int a = 0; a <= j && !blad; a++ )
{
if( pocz > t[a].first )
{
pocz = pocz + (hp[t[a].second][1]-hp[t[a].second][2]);
}
else
{
pocz = hp[t[a].second][1]+1;
}
if( pocz > z )
{
blad = 1;
break;
}
}
if( blad )printf("NIE");
else
{
printf("TAK\n");
for( int a = 1; a <= licz; a++ )printf("%d ", wyn[a]);
for( ; j >= 0; j-- )printf("%d ", t[j].second);
}
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 68 69 70 71 72 73 74 | #include<iostream> #include<cstdio> #include<vector> #include<algorithm> using namespace std; pair<int,int> tab[100001]; pair<int,int> t[100001]; int hp[100001][3], wyn[100001]; int ile = -1, j = -1, licz, n; long long pocz, z; bool blad; int main() { scanf("%d", &n); scanf("%lld", &z); for( int a = 1; a <= n; a++ ) { scanf("%d", &hp[a][1]); scanf("%d", &hp[a][2]); if( hp[a][1] <= hp[a][2] ) { tab[++ile].first = hp[a][1]; tab[ile].second = a; } else { t[++j].first = hp[a][2]+1; t[j].second = a; } } sort( tab, tab+ile+1 ); sort( t, t+j+1 ); for( int a = 0; a <= ile; a++ ) { if( tab[a].first < z ) { wyn[++licz] = tab[a].second; z += (hp[wyn[licz]][2]-hp[wyn[licz]][1]); } else { blad = 1; break; } } for( int a = 0; a <= j && !blad; a++ ) { if( pocz > t[a].first ) { pocz = pocz + (hp[t[a].second][1]-hp[t[a].second][2]); } else { pocz = hp[t[a].second][1]+1; } if( pocz > z ) { blad = 1; break; } } if( blad )printf("NIE"); else { printf("TAK\n"); for( int a = 1; a <= licz; a++ )printf("%d ", wyn[a]); for( ; j >= 0; j-- )printf("%d ", t[j].second); } return 0; } |
English