#include <iostream> #include <cstdio> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <cmath> #include <algorithm> using namespace std; #define REP(i,a,b) for(int i=(a);i<=(b);++i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll long long #define SZ(x) int((x).size()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define SORT(X) sort(X.begin(),X.end()) #define fi first #define se second vector<pair<pair<int,int>,int > > D,U; vector<int> K; int main () { int n; ll k; scanf("%d%lld",&n,&k); FOR(i,n){ int a, b; scanf("%d%d",&a,&b); if(a <= b) D.pb(mp(mp(a,b),i)); else U.pb(mp(mp(b,a),i)); } SORT(D); FOR(i,SZ(D)){ if( k <= D[i].fi.fi){ printf("NIE\n"); return 0; } k -= D[i].fi.fi; k += D[i].fi.se; K.pb(D[i].se); } sort(U.begin(),U.end(),greater<pair<pair<int,int>,int> >()); FOR(i,SZ(U)){ if( k <= U[i].fi.se){ printf("NIE\n"); return 0; } k -= U[i].fi.se; k += U[i].fi.fi; K.pb(U[i].se); } printf("TAK\n"); FOR(i,SZ(K)) printf("%d ", K[i]+1); }
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 | #include <iostream> #include <cstdio> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <cmath> #include <algorithm> using namespace std; #define REP(i,a,b) for(int i=(a);i<=(b);++i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll long long #define SZ(x) int((x).size()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define SORT(X) sort(X.begin(),X.end()) #define fi first #define se second vector<pair<pair<int,int>,int > > D,U; vector<int> K; int main () { int n; ll k; scanf("%d%lld",&n,&k); FOR(i,n){ int a, b; scanf("%d%d",&a,&b); if(a <= b) D.pb(mp(mp(a,b),i)); else U.pb(mp(mp(b,a),i)); } SORT(D); FOR(i,SZ(D)){ if( k <= D[i].fi.fi){ printf("NIE\n"); return 0; } k -= D[i].fi.fi; k += D[i].fi.se; K.pb(D[i].se); } sort(U.begin(),U.end(),greater<pair<pair<int,int>,int> >()); FOR(i,SZ(U)){ if( k <= U[i].fi.se){ printf("NIE\n"); return 0; } k -= U[i].fi.se; k += U[i].fi.fi; K.pb(U[i].se); } printf("TAK\n"); FOR(i,SZ(K)) printf("%d ", K[i]+1); } |