#include<cstdio>
#include<algorithm>
#include<vector>
#define maxN 100010
using namespace std;
vector<int> ans;
vector<pair< pair<int, int >, int> > dod, uj; /// koszt zabicia, bilans /// potion i zabicie
long long hp;
int n;
bool uj_cmp(pair< pair<int, int >, int> a , pair< pair<int, int >, int> b) {
if(a.first.first > b.first.first) return 1;
if(a.first.first == b.first.first and a.first.second > b.first.second ) return 1;
return 0;
}
bool dod_cmp(pair< pair<int, int >, int> a , pair< pair<int, int >, int> b) {
if(a.first.first < b.first.first ) return 1;
if(a.first.first == b.first.first and a.first.second > b.first.second ) return 1;
return 0;
}
int main() {
scanf("%d %lld", &n, &hp);
for(int i=0; i<n; ++i) {
int zab, pot, bil;
scanf("%d%d", &zab, &pot);
bil = pot - zab;
if(bil<0) uj.push_back(make_pair( make_pair(pot, zab), i+1));
else dod.push_back(make_pair( make_pair(zab, bil), i+1) );
}
sort(uj.begin(), uj.end(), uj_cmp);
sort(dod.begin(), dod.end(), dod_cmp);
/* for(int i=0; i<dod.size(); ++i)
printf("%d %d\n", dod[i].first, dod[i].second);
printf("\n\n");
for(int i=0; i<uj.size(); ++i)
printf("%d %d\n", uj[i].first, uj[i].second);
*/
for(int i=0; i<dod.size(); ++i)
if((long long)dod[i].first.first >= hp ) {
printf("NIE\n");
return 0;
}
else {
hp+= dod[i].first.second;
ans.push_back(dod[i].second);
}
for(int i=0; i<uj.size(); ++i)
if((long long)uj[i].first.second >= hp ){
printf("NIE\n");
return 0;
}
else {
hp += (long long) uj[i].first.first - uj[i].first.second;
ans.push_back(uj[i].second);
}
printf("TAK\n");
for(int i=0; i<n ;++i)
printf("%d ", ans[i]);
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 | #include<cstdio> #include<algorithm> #include<vector> #define maxN 100010 using namespace std; vector<int> ans; vector<pair< pair<int, int >, int> > dod, uj; /// koszt zabicia, bilans /// potion i zabicie long long hp; int n; bool uj_cmp(pair< pair<int, int >, int> a , pair< pair<int, int >, int> b) { if(a.first.first > b.first.first) return 1; if(a.first.first == b.first.first and a.first.second > b.first.second ) return 1; return 0; } bool dod_cmp(pair< pair<int, int >, int> a , pair< pair<int, int >, int> b) { if(a.first.first < b.first.first ) return 1; if(a.first.first == b.first.first and a.first.second > b.first.second ) return 1; return 0; } int main() { scanf("%d %lld", &n, &hp); for(int i=0; i<n; ++i) { int zab, pot, bil; scanf("%d%d", &zab, &pot); bil = pot - zab; if(bil<0) uj.push_back(make_pair( make_pair(pot, zab), i+1)); else dod.push_back(make_pair( make_pair(zab, bil), i+1) ); } sort(uj.begin(), uj.end(), uj_cmp); sort(dod.begin(), dod.end(), dod_cmp); /* for(int i=0; i<dod.size(); ++i) printf("%d %d\n", dod[i].first, dod[i].second); printf("\n\n"); for(int i=0; i<uj.size(); ++i) printf("%d %d\n", uj[i].first, uj[i].second); */ for(int i=0; i<dod.size(); ++i) if((long long)dod[i].first.first >= hp ) { printf("NIE\n"); return 0; } else { hp+= dod[i].first.second; ans.push_back(dod[i].second); } for(int i=0; i<uj.size(); ++i) if((long long)uj[i].first.second >= hp ){ printf("NIE\n"); return 0; } else { hp += (long long) uj[i].first.first - uj[i].first.second; ans.push_back(uj[i].second); } printf("TAK\n"); for(int i=0; i<n ;++i) printf("%d ", ans[i]); return 0; } |
polski