#include <cstdio> #include <map> int main () { int t; scanf ("%d", &t); while (t--) { int n, l, a, b; std::map <int, long long> u, v; scanf ("%d", &n); while (n--) { scanf ("%d%d%d", &l, &a, &b); u [a] += l; v [b] += l; } long long p=0, q=0, r=0, s=0, m; auto i = u.begin (), j = v.begin (); while (i != u.end () && j != u.end () && p <= q) { if (r==0) r = i->second; if (s==0) s = j->second; m = std::min (r, s); p += m * i->first; q += m * j->first; r -= m, s -= m; if (r==0) ++i; if (s==0) ++j; } puts (p==q? "TAK": "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 | #include <cstdio> #include <map> int main () { int t; scanf ("%d", &t); while (t--) { int n, l, a, b; std::map <int, long long> u, v; scanf ("%d", &n); while (n--) { scanf ("%d%d%d", &l, &a, &b); u [a] += l; v [b] += l; } long long p=0, q=0, r=0, s=0, m; auto i = u.begin (), j = v.begin (); while (i != u.end () && j != u.end () && p <= q) { if (r==0) r = i->second; if (s==0) s = j->second; m = std::min (r, s); p += m * i->first; q += m * j->first; r -= m, s -= m; if (r==0) ++i; if (s==0) ++j; } puts (p==q? "TAK": "NIE"); } return 0; } |