#include <bits/stdc++.h> using namespace std; int n, m; bool ok = 0; vector<int> pocz, kon; vector<pair<pair<int, int>, int > > prz; int main() { scanf("%d %d", &n, &m); for(int i = 0 ; i < n; i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); pocz.push_back(a), kon.push_back(b); prz.push_back({{a, b}, c}); } for(int i = 0; i < (int)pocz.size(); i++) { for(int j = 0; j < (int)kon.size(); j++) { long long s = 0; int p = pocz[i], y = kon[j]; for(int k = 0; k < (int)prz.size(); k++) { int a = prz[k].first.first, b = prz[k].first.second, c = prz[k].second; if(a >= p && b <= y) { s += b - a; continue; } if(b < p || a > y) continue; int pp = max(a, p), kk = min(b, y); int d = b - a, r = kk - pp; s += max(0, c + r - d); } if(s >(long long)(m * (y - p))) ok = 1; } } ok == 0 ? puts("TAK") : puts("NIE"); 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 | #include <bits/stdc++.h> using namespace std; int n, m; bool ok = 0; vector<int> pocz, kon; vector<pair<pair<int, int>, int > > prz; int main() { scanf("%d %d", &n, &m); for(int i = 0 ; i < n; i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); pocz.push_back(a), kon.push_back(b); prz.push_back({{a, b}, c}); } for(int i = 0; i < (int)pocz.size(); i++) { for(int j = 0; j < (int)kon.size(); j++) { long long s = 0; int p = pocz[i], y = kon[j]; for(int k = 0; k < (int)prz.size(); k++) { int a = prz[k].first.first, b = prz[k].first.second, c = prz[k].second; if(a >= p && b <= y) { s += b - a; continue; } if(b < p || a > y) continue; int pp = max(a, p), kk = min(b, y); int d = b - a, r = kk - pp; s += max(0, c + r - d); } if(s >(long long)(m * (y - p))) ok = 1; } } ok == 0 ? puts("TAK") : puts("NIE"); return 0; } |