#include "cstdio" #include "vector" #include "algorithm" #define f first #define s second using namespace std; long long n, m, a, b, c, koniec; vector < pair < pair< long long, long long>, pair <long long, long long> > > tab; int main() { scanf ("%lld%lld", &n, &m); for (int i = 0; i < n; i++) { scanf ("%lld%lld%lld", &a, &b, &c); tab.push_back(make_pair(make_pair(a,b-a-c), make_pair(b, c))); koniec = max (koniec, b); if (tab[i].f.s < 0) { printf ("NIE\n"); return 0; } } sort (tab.begin(), tab.end()); //printf ("-------\n"); long long poczatek = tab[0].f.f; long long wynik = 0; for (int i = poczatek; i < koniec; i++) { /*for (int ii = 0; ii < n; ii++) { printf ("%lld %lld %lld %lld\n", tab[ii].f.f, tab[ii].f.s, tab[ii].s.f, tab[ii].s.s); } printf("--------\n");*/ long long k = m; for (int j = 0; j < n; j++) { if (i < tab[j].f.f) break; if (i >= tab[j].s.f && tab[j].s.s > 0) { printf ("NIE\n"); return 0; } if (tab[j].s.s > 0 && tab[j].f.f <= i && i < tab[j].s.f) { tab[j].s.s--; if (tab[j].s.s == 0) { tab[j].f.f = 1e9; wynik++; if (wynik == n) { printf ("TAK\n"); return 0; } } if (tab[j].f.f != 1e9) tab[j].f.f = i + 1; k--; } if (k == 0) { for (int q = j + 1; q < n; q++) { if (tab[q].f.f == i) { tab[q].f.f = i + 1; tab[q].f.s--; if (tab[q].f.s < 0) { printf ("NIE\n"); return 0; } } else break; } break; } } sort (tab.begin(), tab.end()); }/* for (int ii = 0; ii < n; ii++) { printf ("%lld %lld %lld %lld\n", tab[ii].f.f, tab[ii].f.s, tab[ii].s.f, tab[ii].s.s); }*/ 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | #include "cstdio" #include "vector" #include "algorithm" #define f first #define s second using namespace std; long long n, m, a, b, c, koniec; vector < pair < pair< long long, long long>, pair <long long, long long> > > tab; int main() { scanf ("%lld%lld", &n, &m); for (int i = 0; i < n; i++) { scanf ("%lld%lld%lld", &a, &b, &c); tab.push_back(make_pair(make_pair(a,b-a-c), make_pair(b, c))); koniec = max (koniec, b); if (tab[i].f.s < 0) { printf ("NIE\n"); return 0; } } sort (tab.begin(), tab.end()); //printf ("-------\n"); long long poczatek = tab[0].f.f; long long wynik = 0; for (int i = poczatek; i < koniec; i++) { /*for (int ii = 0; ii < n; ii++) { printf ("%lld %lld %lld %lld\n", tab[ii].f.f, tab[ii].f.s, tab[ii].s.f, tab[ii].s.s); } printf("--------\n");*/ long long k = m; for (int j = 0; j < n; j++) { if (i < tab[j].f.f) break; if (i >= tab[j].s.f && tab[j].s.s > 0) { printf ("NIE\n"); return 0; } if (tab[j].s.s > 0 && tab[j].f.f <= i && i < tab[j].s.f) { tab[j].s.s--; if (tab[j].s.s == 0) { tab[j].f.f = 1e9; wynik++; if (wynik == n) { printf ("TAK\n"); return 0; } } if (tab[j].f.f != 1e9) tab[j].f.f = i + 1; k--; } if (k == 0) { for (int q = j + 1; q < n; q++) { if (tab[q].f.f == i) { tab[q].f.f = i + 1; tab[q].f.s--; if (tab[q].f.s < 0) { printf ("NIE\n"); return 0; } } else break; } break; } } sort (tab.begin(), tab.end()); }/* for (int ii = 0; ii < n; ii++) { printf ("%lld %lld %lld %lld\n", tab[ii].f.f, tab[ii].f.s, tab[ii].s.f, tab[ii].s.s); }*/ printf ("NIE\n"); return 0; } |