#include <bits/stdc++.h> #define endl "\n" using namespace std; struct task { int ini; int fin; int dur; int luz; }; bool cmp1(const task &a, const task &b) { return (a.luz < b.luz); } bool cmp2(const task &a, const task &b) { return (a.dur > b.dur); } int n,m,p,k,c,minini,maxfin,tao; vector <task> t; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; minini = 1000007; maxfin = 0; for (int i=0; i<n; ++i) { cin>>p>>k>>c; t.push_back({p,k,c,(k-c)}); if (p < minini) minini = p; if (k > maxfin) maxfin = k; } if (!minini) ++minini; /*/ for (int i=0; i<n; ++i) { cout<<t[i].ini<<" "<<t[i].fin<<" "<<t[i].dur<<" "<<t[i].luz<<endl; } /*/ for (tao = minini; tao <= maxfin; ++tao) { /*/ cout<<"time: "<<tao<<endl; for (int yy=0; yy<n; ++yy) { cout<<t[yy].ini<<" "<<t[yy].fin<<" "<<t[yy].dur<<" "<<t[yy].luz<<endl; } cout<<endl<<endl; /*/ int cntr = 0; int i = 0; for (i=0; i<n; ++i) { if (cntr >= m) break; if ((t[i].ini <= tao) && (t[i].fin >= tao) && (t[i].dur > 0)) { ++cntr; --t[i].dur; //cout<<"upd: "<<i<<" cntr = "<<cntr<<endl; } else { --t[i].luz; } } for (int j=i; j<n; ++j) { --t[j].luz; } sort(t.begin(), t.end(), cmp1); } sort(t.begin(), t.end(), cmp2); /*/ cout<<endl<<endl<<endl; for (int i=0; i<n; ++i) { cout<<t[i].ini<<" "<<t[i].fin<<" "<<t[i].dur<<" "<<t[i].luz<<endl; } cout<<endl<<endl; /*/ if (t[0].dur > 0) cout<<"NIE\n"; else cout<<"TAK\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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #include <bits/stdc++.h> #define endl "\n" using namespace std; struct task { int ini; int fin; int dur; int luz; }; bool cmp1(const task &a, const task &b) { return (a.luz < b.luz); } bool cmp2(const task &a, const task &b) { return (a.dur > b.dur); } int n,m,p,k,c,minini,maxfin,tao; vector <task> t; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; minini = 1000007; maxfin = 0; for (int i=0; i<n; ++i) { cin>>p>>k>>c; t.push_back({p,k,c,(k-c)}); if (p < minini) minini = p; if (k > maxfin) maxfin = k; } if (!minini) ++minini; /*/ for (int i=0; i<n; ++i) { cout<<t[i].ini<<" "<<t[i].fin<<" "<<t[i].dur<<" "<<t[i].luz<<endl; } /*/ for (tao = minini; tao <= maxfin; ++tao) { /*/ cout<<"time: "<<tao<<endl; for (int yy=0; yy<n; ++yy) { cout<<t[yy].ini<<" "<<t[yy].fin<<" "<<t[yy].dur<<" "<<t[yy].luz<<endl; } cout<<endl<<endl; /*/ int cntr = 0; int i = 0; for (i=0; i<n; ++i) { if (cntr >= m) break; if ((t[i].ini <= tao) && (t[i].fin >= tao) && (t[i].dur > 0)) { ++cntr; --t[i].dur; //cout<<"upd: "<<i<<" cntr = "<<cntr<<endl; } else { --t[i].luz; } } for (int j=i; j<n; ++j) { --t[j].luz; } sort(t.begin(), t.end(), cmp1); } sort(t.begin(), t.end(), cmp2); /*/ cout<<endl<<endl<<endl; for (int i=0; i<n; ++i) { cout<<t[i].ini<<" "<<t[i].fin<<" "<<t[i].dur<<" "<<t[i].luz<<endl; } cout<<endl<<endl; /*/ if (t[0].dur > 0) cout<<"NIE\n"; else cout<<"TAK\n"; return 0; } |