// Krzysztof Piesiewicz
// Bohater [B]
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX_N = 100007;
class Mon {
public:
int d, a, id;
};
inline bool operator<( Mon a, Mon b ) {
if( a.d <= a.a ) {
if( b.d <= b.a )
return a.d < b.d;
return true;
}
if( b.d <= b.a )
return false;
return a.a > b.a;
}
int n;
long long z;
bool res = true;
Mon m[ MAX_N ];
int main() {
scanf( "%d %Ld", &n, &z );
for( int i = 0; i < n; i++ ) {
scanf( "%d %d", &m[ i ].d, &m[ i ].a );
m[ i ].id = i + 1;
}
sort( m, m + n );
for( int i = 0; i < n; i++ )
if( m[ i ].d < z )
z += m[ i ].a - m[ i ].d;
else
res = false;
if( res ) {
printf( "TAK\n" );
for( int i = 0; i < n; i++ )
printf( "%d ", m[ i ].id );
printf( "\n" );
}
else
printf( "NIE\n" );
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 | // Krzysztof Piesiewicz // Bohater [B] #include <cstdio> #include <algorithm> using namespace std; const int MAX_N = 100007; class Mon { public: int d, a, id; }; inline bool operator<( Mon a, Mon b ) { if( a.d <= a.a ) { if( b.d <= b.a ) return a.d < b.d; return true; } if( b.d <= b.a ) return false; return a.a > b.a; } int n; long long z; bool res = true; Mon m[ MAX_N ]; int main() { scanf( "%d %Ld", &n, &z ); for( int i = 0; i < n; i++ ) { scanf( "%d %d", &m[ i ].d, &m[ i ].a ); m[ i ].id = i + 1; } sort( m, m + n ); for( int i = 0; i < n; i++ ) if( m[ i ].d < z ) z += m[ i ].a - m[ i ].d; else res = false; if( res ) { printf( "TAK\n" ); for( int i = 0; i < n; i++ ) printf( "%d ", m[ i ].id ); printf( "\n" ); } else printf( "NIE\n" ); return 0; } |
English