#include <cstdio> #include <algorithm> #include <vector> using namespace std; bool compare ( pair <pair<int,int>, int> x, pair< pair<int,int>, int> y){ if(x.first.second > y.first.second) return 1; if(x.first.second == y.first.second && x.first.first > y.first.first) return 1; return 0; } int main(){ pair <pair <int,int>, int> x; pair <pair <int,int>, int> y; x = make_pair (make_pair (1,2), 3); y = make_pair (make_pair (1,3), 1); vector<pair< pair<int,int>, int> > A; vector<pair< pair<int,int>, int> > B; int n ,z, d, a; scanf("%d%d", &n, &z); for(int i=1; i<=n; i++){ scanf("%d%d", &d, &a); if(d <= a) A.push_back(make_pair (make_pair (d,a), i)); else B.push_back(make_pair (make_pair (d,a), i)); } sort(A.begin(), A.end()); sort(B.begin(), B.end(), compare); for(int i=0; i<A.size(); i++){ z-= A[i].first.first; if(z<=0){ printf("NIE\n"); return 0; } z += A[i].first.second; } for(int i=0; i<B.size(); i++){ z-= B[i].first.first; if(z<=0){ printf("NIE\n"); return 0; } z += B[i].first.second; } printf("TAK\n"); for(int i=0; i<A.size(); i++) printf("%d ", A[i].second); for(int i=0; i<B.size(); i++) printf("%d ", B[i].second); 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 | #include <cstdio> #include <algorithm> #include <vector> using namespace std; bool compare ( pair <pair<int,int>, int> x, pair< pair<int,int>, int> y){ if(x.first.second > y.first.second) return 1; if(x.first.second == y.first.second && x.first.first > y.first.first) return 1; return 0; } int main(){ pair <pair <int,int>, int> x; pair <pair <int,int>, int> y; x = make_pair (make_pair (1,2), 3); y = make_pair (make_pair (1,3), 1); vector<pair< pair<int,int>, int> > A; vector<pair< pair<int,int>, int> > B; int n ,z, d, a; scanf("%d%d", &n, &z); for(int i=1; i<=n; i++){ scanf("%d%d", &d, &a); if(d <= a) A.push_back(make_pair (make_pair (d,a), i)); else B.push_back(make_pair (make_pair (d,a), i)); } sort(A.begin(), A.end()); sort(B.begin(), B.end(), compare); for(int i=0; i<A.size(); i++){ z-= A[i].first.first; if(z<=0){ printf("NIE\n"); return 0; } z += A[i].first.second; } for(int i=0; i<B.size(); i++){ z-= B[i].first.first; if(z<=0){ printf("NIE\n"); return 0; } z += B[i].first.second; } printf("TAK\n"); for(int i=0; i<A.size(); i++) printf("%d ", A[i].second); for(int i=0; i<B.size(); i++) printf("%d ", B[i].second); printf("\n"); return 0; } |