#include <cstdio> #include <vector> #include <map> #include <algorithm> #include <set> #include <queue> using namespace std; typedef vector<int> VI; typedef vector<bool> bit_vector; #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define VAR(v, n) typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define FOREACH_R(i, c) for(VAR(i, (c).rbegin()); i != (c).rend(); ++i) #define PB push_back struct TPotwory { int i; int D; // obrazenia int A; // punkty zdrowia TPotwory() {} TPotwory(int _i, int _D, int _A) : i(_i),D(_D),A(_A) {} bool operator() (const TPotwory &p1, const TPotwory &p2) const { if (p1.D < p1.A && p2.D < p2.A) { return p1.D < p2.D; } else if (p1.D < p1.A) { return true; } else if (p2.D < p2.A) { return false; } return (p1.D==p2.D && p1.A>p2.A) || p1.A>=p2.A; } }; bool func(vector<int> &v) { int n; long long z; int d, a; vector<TPotwory> potwory; scanf("%d%lld",&n,&z); for (int i=1;i<=n;++i) { scanf("%d%d", &d, &a); potwory.PB(TPotwory(i,d,a)); } sort(ALL(potwory), TPotwory()); FOREACH(it, potwory) { z = z - it->D; if (z<=0) return false; v.PB(it->i); // printf("%d: %d %d\n", it->i, it->D, it->A); z = z + it->A; } return true; } int main() { vector<int> v; bool b = func(v); if (b==true) { printf("TAK\n"); FOREACH(it, v) { printf("%d ", *it); } } 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 74 75 76 77 78 79 | #include <cstdio> #include <vector> #include <map> #include <algorithm> #include <set> #include <queue> using namespace std; typedef vector<int> VI; typedef vector<bool> bit_vector; #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define VAR(v, n) typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define FOREACH_R(i, c) for(VAR(i, (c).rbegin()); i != (c).rend(); ++i) #define PB push_back struct TPotwory { int i; int D; // obrazenia int A; // punkty zdrowia TPotwory() {} TPotwory(int _i, int _D, int _A) : i(_i),D(_D),A(_A) {} bool operator() (const TPotwory &p1, const TPotwory &p2) const { if (p1.D < p1.A && p2.D < p2.A) { return p1.D < p2.D; } else if (p1.D < p1.A) { return true; } else if (p2.D < p2.A) { return false; } return (p1.D==p2.D && p1.A>p2.A) || p1.A>=p2.A; } }; bool func(vector<int> &v) { int n; long long z; int d, a; vector<TPotwory> potwory; scanf("%d%lld",&n,&z); for (int i=1;i<=n;++i) { scanf("%d%d", &d, &a); potwory.PB(TPotwory(i,d,a)); } sort(ALL(potwory), TPotwory()); FOREACH(it, potwory) { z = z - it->D; if (z<=0) return false; v.PB(it->i); // printf("%d: %d %d\n", it->i, it->D, it->A); z = z + it->A; } return true; } int main() { vector<int> v; bool b = func(v); if (b==true) { printf("TAK\n"); FOREACH(it, v) { printf("%d ", *it); } } else { printf("NIE\n"); } return 0; } |