/* Notice: - This account submits solutions that result from the collaboration of two (non-Polish) individuals. - We acknowledge that our participation is completely unofficial. - We just want to be able to submit our solutions until the end of the week. Thank you :)! */ #include <cstdio> /* Notice: - This account submits solutions that result from the collaboration of two (non-Polish) individuals. - We acknowledge that our participation is completely unofficial. - We just want to be able to submit our solutions until the end of the week. Thank you :)! */ #include <cstring> #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long int64; const int64 kInf = (1LL<<60); struct Cup { int64 v, t; int type; }; string Solve(istream& cin) { int n; cin >> n; vector<Cup> cups; for (int i = 1; i <= n; ++i) { int64 v, t1, t2; cin >> v >> t1 >> t2; cups.push_back(Cup{v, t1, 0}); cups.push_back(Cup{v, t2, 1}); } sort(cups.begin(), cups.end(), [&](const Cup& a, const Cup& b) { return a.t < b.t; }); int64 cx = 0, cy = 0; for (auto &cup : cups) { if (cup.type == 0) { if (cx > 0 && cy < cx * cup.t) { return "NIE"; } cx -= cup.v; cy -= cup.v * cup.t; } else { cx += cup.v; cy += cup.v * cup.t; } } if (cx == 0 && cy == 0) return "TAK"; return "NIE"; } int main() { int test; cin >> test; for (;test; --test) { cout << Solve(cin) << "\n"; } }
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 | /* Notice: - This account submits solutions that result from the collaboration of two (non-Polish) individuals. - We acknowledge that our participation is completely unofficial. - We just want to be able to submit our solutions until the end of the week. Thank you :)! */ #include <cstdio> /* Notice: - This account submits solutions that result from the collaboration of two (non-Polish) individuals. - We acknowledge that our participation is completely unofficial. - We just want to be able to submit our solutions until the end of the week. Thank you :)! */ #include <cstring> #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long int64; const int64 kInf = (1LL<<60); struct Cup { int64 v, t; int type; }; string Solve(istream& cin) { int n; cin >> n; vector<Cup> cups; for (int i = 1; i <= n; ++i) { int64 v, t1, t2; cin >> v >> t1 >> t2; cups.push_back(Cup{v, t1, 0}); cups.push_back(Cup{v, t2, 1}); } sort(cups.begin(), cups.end(), [&](const Cup& a, const Cup& b) { return a.t < b.t; }); int64 cx = 0, cy = 0; for (auto &cup : cups) { if (cup.type == 0) { if (cx > 0 && cy < cx * cup.t) { return "NIE"; } cx -= cup.v; cy -= cup.v * cup.t; } else { cx += cup.v; cy += cup.v * cup.t; } } if (cx == 0 && cy == 0) return "TAK"; return "NIE"; } int main() { int test; cin >> test; for (;test; --test) { cout << Solve(cin) << "\n"; } } |