#include <iostream> using namespace std; struct section { int a, b, p; }; int main() { int n, m, sum, a, b, p; bool ok = true; section s [100]; cin>>n>>m; for (int i = 0; i < n; ++i) { cin>>s[i].a>>s[i].b>>s[i].p; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { sum = 0; int a = s[i].a; int b = s[j].b; if (b < a) break; for (int k = 0; k < n; ++k) { //cout<<"przedzial: "<<k<<" "<<s[k].a<<" "<<s[k].b<<endl; int beg = s[k].a; int end = s[k].b; int out = 0; if (beg < a) out = a-beg; if (end > b) out += end-b; if (out < s[k].p) { sum += s[k].p - out; //cout<<"przedzial: "<<k<<"dodaje: "<<sum<<endl; } } //cout<<"sum: "<<sum<< " length: "<<(b-a+1)*m<<endl; if (sum > (b-a) * m) { ok = false; } } } if (ok) cout<<"TAK"<<endl; else cout<<"NIE"<<endl; 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 | #include <iostream> using namespace std; struct section { int a, b, p; }; int main() { int n, m, sum, a, b, p; bool ok = true; section s [100]; cin>>n>>m; for (int i = 0; i < n; ++i) { cin>>s[i].a>>s[i].b>>s[i].p; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { sum = 0; int a = s[i].a; int b = s[j].b; if (b < a) break; for (int k = 0; k < n; ++k) { //cout<<"przedzial: "<<k<<" "<<s[k].a<<" "<<s[k].b<<endl; int beg = s[k].a; int end = s[k].b; int out = 0; if (beg < a) out = a-beg; if (end > b) out += end-b; if (out < s[k].p) { sum += s[k].p - out; //cout<<"przedzial: "<<k<<"dodaje: "<<sum<<endl; } } //cout<<"sum: "<<sum<< " length: "<<(b-a+1)*m<<endl; if (sum > (b-a) * m) { ok = false; } } } if (ok) cout<<"TAK"<<endl; else cout<<"NIE"<<endl; return 0; } |