#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
struct str{
long long suma,d,a;
int i;
str(long long d=0, long long a=0, int i=0): d(d), a(a), i(i) {}
};
bool cmp_easy(str i, str j){ return (i.d-j.d)? i.d<j.d : i.a>j.a; }
bool cmp_hard(str i, str j){ return (i.a-j.a)? i.a<j.a : i.d<j.d; }
long long n,z;
vector<str> hard,easy;
int main(){
scanf("%lld%lld", &n, &z);
for (int i=0; i<n; ++i){
long long d,a;
scanf("%lld%lld", &d, &a);
if (a-d>=0) easy.push_back(str(d,a,i));
else hard.push_back(str(d,a,i));
}
sort(easy.begin(),easy.end(),cmp_easy);
sort(hard.begin(),hard.end(),cmp_hard);
for (int i=0; i<easy.size(); ++i){
z-=easy[i].d;
if (z<=0){
printf("NIE\n");
return 0;
}
z+=easy[i].a;
}
long long temp=1;
for (int i=0; i<hard.size(); ++i){
temp-=hard[i].a;
if (temp<=0) temp=1;
temp+=hard[i].d;
}
if (temp<=z){
printf("TAK\n");
for (int i=0; i<easy.size(); ++i)
printf("%d ", easy[i].i+1);
for (int i=hard.size()-1; i>=0; --i)
printf("%d ", hard[i].i+1);
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 | #include <cstdio> #include <algorithm> #include <vector> using namespace std; struct str{ long long suma,d,a; int i; str(long long d=0, long long a=0, int i=0): d(d), a(a), i(i) {} }; bool cmp_easy(str i, str j){ return (i.d-j.d)? i.d<j.d : i.a>j.a; } bool cmp_hard(str i, str j){ return (i.a-j.a)? i.a<j.a : i.d<j.d; } long long n,z; vector<str> hard,easy; int main(){ scanf("%lld%lld", &n, &z); for (int i=0; i<n; ++i){ long long d,a; scanf("%lld%lld", &d, &a); if (a-d>=0) easy.push_back(str(d,a,i)); else hard.push_back(str(d,a,i)); } sort(easy.begin(),easy.end(),cmp_easy); sort(hard.begin(),hard.end(),cmp_hard); for (int i=0; i<easy.size(); ++i){ z-=easy[i].d; if (z<=0){ printf("NIE\n"); return 0; } z+=easy[i].a; } long long temp=1; for (int i=0; i<hard.size(); ++i){ temp-=hard[i].a; if (temp<=0) temp=1; temp+=hard[i].d; } if (temp<=z){ printf("TAK\n"); for (int i=0; i<easy.size(); ++i) printf("%d ", easy[i].i+1); for (int i=hard.size()-1; i>=0; --i) printf("%d ", hard[i].i+1); printf("\n"); } else printf("NIE\n"); return 0; } |
English