#include <cstdio>
#include <algorithm>
using namespace std;
long long int potrzeba[100005], daje[100005],z;
int tab[100005],ile;
short int np[100005];
struct comp{
bool operator ()(int const& a, int const& b){
if(np[a]>np[b]) return true;
if(np[a]<np[b]) return false;
if(np[a]==1){
if(potrzeba[a]<potrzeba[b]) return true;
return false;
}
//if(potrzeba[a]>potrzeba[b]) return true;
if(/*potrzeba[a]==potrzeba[b] &&*/ daje[a]>daje[b]) return true;
return false;
}
};
int main(){
scanf("%d %lld", &ile, &z);
for(int i=0; i<ile; i++){
scanf("%lld %lld", &potrzeba[i], &daje[i]);
tab[i]=i;
np[i] = (daje[i]>=potrzeba[i] ? 1 : 0);
}
sort(tab,tab+ile,comp());
for(int i=0; i<ile; i++){
z-=potrzeba[tab[i]];
if(z<=0) { printf("NIE"); return 0; }
z+=daje[tab[i]];
}
printf("TAK\n");
for(int i=0; i<ile; i++)
printf("%d ",tab[i]+1);
}
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 | #include <cstdio> #include <algorithm> using namespace std; long long int potrzeba[100005], daje[100005],z; int tab[100005],ile; short int np[100005]; struct comp{ bool operator ()(int const& a, int const& b){ if(np[a]>np[b]) return true; if(np[a]<np[b]) return false; if(np[a]==1){ if(potrzeba[a]<potrzeba[b]) return true; return false; } //if(potrzeba[a]>potrzeba[b]) return true; if(/*potrzeba[a]==potrzeba[b] &&*/ daje[a]>daje[b]) return true; return false; } }; int main(){ scanf("%d %lld", &ile, &z); for(int i=0; i<ile; i++){ scanf("%lld %lld", &potrzeba[i], &daje[i]); tab[i]=i; np[i] = (daje[i]>=potrzeba[i] ? 1 : 0); } sort(tab,tab+ile,comp()); for(int i=0; i<ile; i++){ z-=potrzeba[tab[i]]; if(z<=0) { printf("NIE"); return 0; } z+=daje[tab[i]]; } printf("TAK\n"); for(int i=0; i<ile; i++) printf("%d ",tab[i]+1); } |
English