#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PI;
#define MP make_pair
#define PB push_back
#define SD second
#define FT first
int k,n,m,q;
const int N = 100003;
const LL INF = 2000000000000000000LL;
priority_queue<PI,vector<PI>, greater<PI> > wart;
vector<PI> zle;
PI mon[N];
vector<int>res;
LL z;
int main() {
scanf("%d%d",&n,&z);
for(int i=0;i<n;i++) {
int a,b;
scanf("%d%d",&a,&b);
if(b-a >= 0)
wart.push(MP(a,i));
else {
zle.PB(MP(a-(a-b),i));
}
mon[i] = MP(a,b);
}
int pokonal = 0;
sort(zle.begin(),zle.end());
while(wart.empty() == 0 && wart.top().FT < z) {
z += mon[wart.top().SD].SD - mon[wart.top().SD].FT;
res.PB(wart.top().SD);
wart.pop();
pokonal++;
}
bool ok = false;
if(wart.empty()) {
for(int i=zle.size()-1;i>=0;i--) {
if(z > mon[zle[i].SD].FT) {
z -= mon[zle[i].SD].FT - mon[zle[i].SD].SD;
pokonal++;
res.PB(zle[i].SD);
}
}
}
printf("%s\n",pokonal == n ? "TAK" : "NIE");
if(pokonal == n){
for(int i=0;i<res.size();i++) printf("%d ",res[i]+1); printf("\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 | #include <cstdio> #include <map> #include <algorithm> #include <vector> #include <queue> using namespace std; typedef long long LL; typedef pair<LL,LL> PI; #define MP make_pair #define PB push_back #define SD second #define FT first int k,n,m,q; const int N = 100003; const LL INF = 2000000000000000000LL; priority_queue<PI,vector<PI>, greater<PI> > wart; vector<PI> zle; PI mon[N]; vector<int>res; LL z; int main() { scanf("%d%d",&n,&z); for(int i=0;i<n;i++) { int a,b; scanf("%d%d",&a,&b); if(b-a >= 0) wart.push(MP(a,i)); else { zle.PB(MP(a-(a-b),i)); } mon[i] = MP(a,b); } int pokonal = 0; sort(zle.begin(),zle.end()); while(wart.empty() == 0 && wart.top().FT < z) { z += mon[wart.top().SD].SD - mon[wart.top().SD].FT; res.PB(wart.top().SD); wart.pop(); pokonal++; } bool ok = false; if(wart.empty()) { for(int i=zle.size()-1;i>=0;i--) { if(z > mon[zle[i].SD].FT) { z -= mon[zle[i].SD].FT - mon[zle[i].SD].SD; pokonal++; res.PB(zle[i].SD); } } } printf("%s\n",pokonal == n ? "TAK" : "NIE"); if(pokonal == n){ for(int i=0;i<res.size();i++) printf("%d ",res[i]+1); printf("\n"); } return 0; } |
English