#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int MX=100005;
int wynikowa[MX];
pair<int,pair<int,int> > t[MX], opylajace[MX];
int main(){
int N, HP;
scanf("%d%d", &N, &HP);
int k=HP;
int y=0, i, x=0;
long long suma=0;
for(i=0;i<N;++i){
int a,b;
scanf("%d%d", &a, &b);
if(b>=a){
opylajace[x].first=a;
opylajace[x].second.first=b;
opylajace[x].second.second=i+1;
++x;
}
else{
t[y].first=b;
t[y].second.first=a;
t[y].second.second=i+1;
++y;
}
suma+=a-b;
}
if(k<=suma){
printf("NIE\n");
return 0;
}
sort(opylajace,opylajace+x);
sort(t,t+y);
for(int j=0;j<x;++j){
if(opylajace[j].first>=k){
printf("NIE\n");
return 0;
}
else{
k+=opylajace[j].second.first;
wynikowa[j]=opylajace[j].second.second;
}
}
for(int j=y;j>0;--j){
if(t[j-1].second.first>=k){
printf("NIE\n");
return 0;
}
else{
k+=t[j-1].first-t[j-1].second.first;
wynikowa[x]=t[j-1].second.second;
}
++x;
//printf("%d\n", t[j].first);
}
printf("TAK\n");
for(int j=0;j<N;++j){
printf("%d ", wynikowa[j]);
}
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 | #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int MX=100005; int wynikowa[MX]; pair<int,pair<int,int> > t[MX], opylajace[MX]; int main(){ int N, HP; scanf("%d%d", &N, &HP); int k=HP; int y=0, i, x=0; long long suma=0; for(i=0;i<N;++i){ int a,b; scanf("%d%d", &a, &b); if(b>=a){ opylajace[x].first=a; opylajace[x].second.first=b; opylajace[x].second.second=i+1; ++x; } else{ t[y].first=b; t[y].second.first=a; t[y].second.second=i+1; ++y; } suma+=a-b; } if(k<=suma){ printf("NIE\n"); return 0; } sort(opylajace,opylajace+x); sort(t,t+y); for(int j=0;j<x;++j){ if(opylajace[j].first>=k){ printf("NIE\n"); return 0; } else{ k+=opylajace[j].second.first; wynikowa[j]=opylajace[j].second.second; } } for(int j=y;j>0;--j){ if(t[j-1].second.first>=k){ printf("NIE\n"); return 0; } else{ k+=t[j-1].first-t[j-1].second.first; wynikowa[x]=t[j-1].second.second; } ++x; //printf("%d\n", t[j].first); } printf("TAK\n"); for(int j=0;j<N;++j){ printf("%d ", wynikowa[j]); } return 0; } |
English