#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
struct pot{
int ind;
long long obr;
long long eli;
};
pot pom;
bool zle;
vector<pot> zysk;
vector<pot> strata;
vector<int> wynik;
int n;
long long z;
bool cmp1(const pot &a, const pot &b){
if(a.obr < b.obr)return 1;
return 0;
}
bool cmp2(const pot &a, const pot &b){
if(a.eli > b.eli)return 1;
return 0;
}
int main(){
scanf("%d",&n);
scanf("%lld",&z);
for(int i=1;i<=n;i++){
pom.ind = i;
scanf("%lld",&pom.obr);
scanf("%lld",&pom.eli);
if(pom.eli >= pom.obr){
zysk.push_back(pom);
}
else strata.push_back(pom);
}
sort(zysk.begin(),zysk.end(),cmp1);
sort(strata.begin(),strata.end(),cmp2);
for(int i=0;i<zysk.size();i++){
z -= zysk[i].obr;
if(z <= 0){
zle = 1;
break;
}
z += zysk[i].eli;
wynik.push_back(zysk[i].ind);
}
for(int i=0;i<strata.size();i++){
z -= strata[i].obr;
if(z <= 0){
zle = 1;
break;
}
z += strata[i].eli;
wynik.push_back(strata[i].ind);
}
if(zle == 1)printf("NIE\n");
else{
printf("TAK\n");
for(int i=0;i<wynik.size();i++){
printf("%d ",wynik[i]);
}
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #include<cstdio> #include<algorithm> #include<vector> using namespace std; struct pot{ int ind; long long obr; long long eli; }; pot pom; bool zle; vector<pot> zysk; vector<pot> strata; vector<int> wynik; int n; long long z; bool cmp1(const pot &a, const pot &b){ if(a.obr < b.obr)return 1; return 0; } bool cmp2(const pot &a, const pot &b){ if(a.eli > b.eli)return 1; return 0; } int main(){ scanf("%d",&n); scanf("%lld",&z); for(int i=1;i<=n;i++){ pom.ind = i; scanf("%lld",&pom.obr); scanf("%lld",&pom.eli); if(pom.eli >= pom.obr){ zysk.push_back(pom); } else strata.push_back(pom); } sort(zysk.begin(),zysk.end(),cmp1); sort(strata.begin(),strata.end(),cmp2); for(int i=0;i<zysk.size();i++){ z -= zysk[i].obr; if(z <= 0){ zle = 1; break; } z += zysk[i].eli; wynik.push_back(zysk[i].ind); } for(int i=0;i<strata.size();i++){ z -= strata[i].obr; if(z <= 0){ zle = 1; break; } z += strata[i].eli; wynik.push_back(strata[i].ind); } if(zle == 1)printf("NIE\n"); else{ printf("TAK\n"); for(int i=0;i<wynik.size();i++){ printf("%d ",wynik[i]); } printf("\n"); } return 0; } |
English