// // main.cpp // boh // // Created by acon on 14/05/14. // Copyright (c) 2014 acon. All rights reserved. // #include <iostream> #include <vector> #include <algorithm> using namespace std; bool pairCompare(const pair<int,int> fe, const pair<int,int> se) { return fe.second > se.second; } int main(int argc, const char * argv[]) { vector< pair<int,int> > way; int n,z; scanf("%i %i",&n,&z); for(int i = 0;i<n;i++) { int d,a; scanf("%i %i",&d,&a); way.push_back(make_pair(i+1, a-d)); } sort(way.begin(), way.end(), pairCompare); int t = z; for(int i = 0;i<way.size();i++) { t+=way[i].second; } if(t<0) { printf("NIE"); } vector<int> ret; for(int i = 0;i<way.size();i++) { z+=way[i].second; if(z<=0) break; ret.push_back(way[i].first); } if(ret.size() == way.size()) { printf("TAK\n"); for(int i = 0;i<ret.size();i++) { printf("%i ",ret[i]); } } 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | // // main.cpp // boh // // Created by acon on 14/05/14. // Copyright (c) 2014 acon. All rights reserved. // #include <iostream> #include <vector> #include <algorithm> using namespace std; bool pairCompare(const pair<int,int> fe, const pair<int,int> se) { return fe.second > se.second; } int main(int argc, const char * argv[]) { vector< pair<int,int> > way; int n,z; scanf("%i %i",&n,&z); for(int i = 0;i<n;i++) { int d,a; scanf("%i %i",&d,&a); way.push_back(make_pair(i+1, a-d)); } sort(way.begin(), way.end(), pairCompare); int t = z; for(int i = 0;i<way.size();i++) { t+=way[i].second; } if(t<0) { printf("NIE"); } vector<int> ret; for(int i = 0;i<way.size();i++) { z+=way[i].second; if(z<=0) break; ret.push_back(way[i].first); } if(ret.size() == way.size()) { printf("TAK\n"); for(int i = 0;i<ret.size();i++) { printf("%i ",ret[i]); } } else { printf("NIE\n"); } return 0; } |