// Krzysztof Baranski
////////////////////////////////////////////////////////////////////
// //
// HEADERS //
// //
////////////////////////////////////////////////////////////////////
// includes
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <complex>
#include <iterator>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <cstdlib>
using namespace std;
// defines
#define FOR(x,b,e) for(int x=b; x<=(e); ++x)
#define FORD(x,b,e) for(int x=(b); x>=(e); --x)
#define FORK(x,b,e,k) for(int x=b; x<=(e); x+=k)
#define REP(x,n) for(int x=0; x<(n); ++x)
#define VAR(v,n) decltype(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define CLEAR(x) while(!(x).empty())(x).pop()
#define PB push_back
#define MP make_pair
#define ND second
#define ST first
#define POP(q) q.top(); q.pop()
#define __START__ int __z_;scanf("%d\n",&__z_);while(__z_--){
#define __STOP__ }return 0;
#define _INT(x) int x; scanf("%d",&x)
// typedef
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<bool> VB;
typedef stack<int> SI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef stack<PII> SPII;
typedef vector<char> VC;
typedef vector<VC> VVC;
// consts
const int INF = 1000000001;
const long long LINF = 1000000000000000001;
const double EPS = 10e-9;
////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------//
////////////////////////////////////////////////////////////////////
struct Monster {
int id,d,a;
Monster(int id,int d,int a):id(id),d(d),a(a){}
};
bool operator<(const Monster&m1,const Monster&m2){return m1.d<m2.d;}
struct _ROSNACO_PO_D {
bool operator() (const Monster&m1,const Monster&m2) { return m1.d<m2.d;}
} ROSNACO_PO_D;
struct _MALEJACO_PO_A {
bool operator() (const Monster&m1,const Monster&m2) { return m1.a>m2.a;}
} MALEJACO_PO_A;
//==================================================================| MAIN
int main() {
_INT(n);_INT(z);
vector<Monster> skok_dodatni;
vector<Monster> skok_zerowy;
vector<Monster> skok_ujemny;
VI kolejnosc;
REP(i,n) {
_INT(d);_INT(a);
if(a-d>0) skok_dodatni.emplace_back(i+1,d,a);
else if(a-d<0) skok_ujemny.emplace_back(i+1,d,a);
else skok_zerowy.emplace_back(i+1,d,a);
}
LL zycie = z;
bool mozna = true;
// skok dodatni
sort(ALL(skok_dodatni),ROSNACO_PO_D);
FOREACH(m,skok_dodatni) {
if(m->d >= zycie) {mozna=false;break;}
zycie+=(m->a - m->d);
kolejnosc.PB(m->id);
}
// skok zerowy
FOREACH(m,skok_zerowy) if(!mozna || m->d >= zycie) {
mozna=false;break;
} else kolejnosc.PB(m->id);
// skok ujemny
if(mozna) sort(ALL(skok_ujemny),MALEJACO_PO_A);
FOREACH(m,skok_ujemny) {
if(!mozna || m->d >= zycie) {mozna=false;break;}
zycie+=(m->a - m->d);
kolejnosc.PB(m->id);
}
if(mozna) {
printf("TAK\n");
FOREACH(s,kolejnosc) printf("%d ",*s);
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | // Krzysztof Baranski //////////////////////////////////////////////////////////////////// // // // HEADERS // // // //////////////////////////////////////////////////////////////////// // includes #include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <complex> #include <iterator> #include <set> #include <bitset> #include <map> #include <stack> #include <list> #include <queue> #include <deque> #include <cstdlib> using namespace std; // defines #define FOR(x,b,e) for(int x=b; x<=(e); ++x) #define FORD(x,b,e) for(int x=(b); x>=(e); --x) #define FORK(x,b,e,k) for(int x=b; x<=(e); x+=k) #define REP(x,n) for(int x=0; x<(n); ++x) #define VAR(v,n) decltype(n) v=(n) #define ALL(c) c.begin(),c.end() #define SIZE(x) (int)x.size() #define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i) #define CLEAR(x) while(!(x).empty())(x).pop() #define PB push_back #define MP make_pair #define ND second #define ST first #define POP(q) q.top(); q.pop() #define __START__ int __z_;scanf("%d\n",&__z_);while(__z_--){ #define __STOP__ }return 0; #define _INT(x) int x; scanf("%d",&x) // typedef typedef long long LL; typedef unsigned long long ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<bool> VB; typedef stack<int> SI; typedef pair<int,int> PII; typedef vector<PII> VPII; typedef stack<PII> SPII; typedef vector<char> VC; typedef vector<VC> VVC; // consts const int INF = 1000000001; const long long LINF = 1000000000000000001; const double EPS = 10e-9; //////////////////////////////////////////////////////////////////// //----------------------------------------------------------------// //////////////////////////////////////////////////////////////////// struct Monster { int id,d,a; Monster(int id,int d,int a):id(id),d(d),a(a){} }; bool operator<(const Monster&m1,const Monster&m2){return m1.d<m2.d;} struct _ROSNACO_PO_D { bool operator() (const Monster&m1,const Monster&m2) { return m1.d<m2.d;} } ROSNACO_PO_D; struct _MALEJACO_PO_A { bool operator() (const Monster&m1,const Monster&m2) { return m1.a>m2.a;} } MALEJACO_PO_A; //==================================================================| MAIN int main() { _INT(n);_INT(z); vector<Monster> skok_dodatni; vector<Monster> skok_zerowy; vector<Monster> skok_ujemny; VI kolejnosc; REP(i,n) { _INT(d);_INT(a); if(a-d>0) skok_dodatni.emplace_back(i+1,d,a); else if(a-d<0) skok_ujemny.emplace_back(i+1,d,a); else skok_zerowy.emplace_back(i+1,d,a); } LL zycie = z; bool mozna = true; // skok dodatni sort(ALL(skok_dodatni),ROSNACO_PO_D); FOREACH(m,skok_dodatni) { if(m->d >= zycie) {mozna=false;break;} zycie+=(m->a - m->d); kolejnosc.PB(m->id); } // skok zerowy FOREACH(m,skok_zerowy) if(!mozna || m->d >= zycie) { mozna=false;break; } else kolejnosc.PB(m->id); // skok ujemny if(mozna) sort(ALL(skok_ujemny),MALEJACO_PO_A); FOREACH(m,skok_ujemny) { if(!mozna || m->d >= zycie) {mozna=false;break;} zycie+=(m->a - m->d); kolejnosc.PB(m->id); } if(mozna) { printf("TAK\n"); FOREACH(s,kolejnosc) printf("%d ",*s); printf("\n"); } else printf("NIE\n"); return 0; } |
English