#define _CRT_SECURE_NO_WARNINGS 1
#define _WINSOCK_DEPRECATED_NO_WARNINGS 1
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while (t-- > 0)
{
int n;
long long swa = 0, swb = 0;
map<int, int> m;
scanf("%d", &n);
for (long i = 0; i < n; ++i)
{
long long l, a, b;
scanf("%lld%lld%lld", &l, &a, &b);
swa += l * a;
swb += l * b;
m[a] += l;
m[b] -= l;
}
if (swa != swb)
{
printf("NIE\n");
continue;
}
int first = 0;
int last = 0;
for (auto const& x : m)
{
if (x.second != 0)
{
last = x.second;
if (first == 0)
{
first = x.second;
}
}
}
if ((first < 0) || (last < 0))
{
printf("NIE\n");
continue;
}
printf("TAK\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 | #define _CRT_SECURE_NO_WARNINGS 1 #define _WINSOCK_DEPRECATED_NO_WARNINGS 1 #include <cstdio> #include <algorithm> #include <vector> #include <map> using namespace std; int main() { int t; scanf("%d", &t); while (t-- > 0) { int n; long long swa = 0, swb = 0; map<int, int> m; scanf("%d", &n); for (long i = 0; i < n; ++i) { long long l, a, b; scanf("%lld%lld%lld", &l, &a, &b); swa += l * a; swb += l * b; m[a] += l; m[b] -= l; } if (swa != swb) { printf("NIE\n"); continue; } int first = 0; int last = 0; for (auto const& x : m) { if (x.second != 0) { last = x.second; if (first == 0) { first = x.second; } } } if ((first < 0) || (last < 0)) { printf("NIE\n"); continue; } printf("TAK\n"); } } |
English