#include <stdio.h> #include <algorithm> struct Potwor { int sila; int eliksir; int indeks; }; struct Part { bool operator()(Potwor const & lhs) const { return lhs.eliksir >= lhs.sila; } }; struct Pos { bool operator()(Potwor const & lhs, Potwor const & rhs) const { return lhs.sila < rhs.sila; } }; struct Neg { bool operator()(Potwor const & lhs, Potwor const & rhs) const { return lhs.eliksir > rhs.eliksir || lhs.eliksir == rhs.eliksir && lhs.sila < rhs.sila; } }; Potwor positives[100001]; int main() { int ile, life, d, a, P = 0; scanf("%d %d\n", &ile, &life); for(int i = 0 ; i < ile ; ++i) { scanf("%d %d\n", &d, &a); positives[P].sila = d; positives[P].eliksir = a; positives[P].indeks = i+1; ++P; } Potwor* part = std::partition(positives, positives+P, Part()); std::sort(positives, part, Pos()); std::sort(part, positives+P, Neg()); for(Potwor* i = positives ; i != positives+P ; ++i) { if(life <= i->sila) { printf("NIE\n"); return 0; } life += i->eliksir - i->sila; } printf("TAK\n%d", positives[0].indeks); for(int i = 1 ; i < P ; ++i) { printf(" %d", positives[i].indeks); } 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #include <stdio.h> #include <algorithm> struct Potwor { int sila; int eliksir; int indeks; }; struct Part { bool operator()(Potwor const & lhs) const { return lhs.eliksir >= lhs.sila; } }; struct Pos { bool operator()(Potwor const & lhs, Potwor const & rhs) const { return lhs.sila < rhs.sila; } }; struct Neg { bool operator()(Potwor const & lhs, Potwor const & rhs) const { return lhs.eliksir > rhs.eliksir || lhs.eliksir == rhs.eliksir && lhs.sila < rhs.sila; } }; Potwor positives[100001]; int main() { int ile, life, d, a, P = 0; scanf("%d %d\n", &ile, &life); for(int i = 0 ; i < ile ; ++i) { scanf("%d %d\n", &d, &a); positives[P].sila = d; positives[P].eliksir = a; positives[P].indeks = i+1; ++P; } Potwor* part = std::partition(positives, positives+P, Part()); std::sort(positives, part, Pos()); std::sort(part, positives+P, Neg()); for(Potwor* i = positives ; i != positives+P ; ++i) { if(life <= i->sila) { printf("NIE\n"); return 0; } life += i->eliksir - i->sila; } printf("TAK\n%d", positives[0].indeks); for(int i = 1 ; i < P ; ++i) { printf(" %d", positives[i].indeks); } printf("\n"); return 0; } |