#include <cstdio> #include <algorithm> using namespace std; int ile, dzi, sum; int main() { scanf ("%d", &ile); for (int i = 0; i < ile; i++) { scanf ("%d", &dzi); pair <int, int> dos [dzi], ocz [dzi], pod [dzi], chl [dzi]; for (int j = 0; j < dzi; j++) { scanf ("%d%d%d", &dos [j].second, &dos [j].first, &ocz [j].first); ocz [j].second = dos [j].second; } sort (dos, dos + dzi); sort (ocz, ocz + dzi); sum = 0; for (int j = 0; j < dzi; j++) { sum = sum + dos [j].second * dos [j].first; } for (int j = 0; j < dzi; j++) { sum = sum - ocz [j].second * ocz [j].first; } if (sum == 0 && dos [0].first <= ocz [0].first && dos [dzi - 1].first >= ocz [dzi - 1].first) { printf ("TAK\n"); } else { printf ("NIE\n"); } } 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 | #include <cstdio> #include <algorithm> using namespace std; int ile, dzi, sum; int main() { scanf ("%d", &ile); for (int i = 0; i < ile; i++) { scanf ("%d", &dzi); pair <int, int> dos [dzi], ocz [dzi], pod [dzi], chl [dzi]; for (int j = 0; j < dzi; j++) { scanf ("%d%d%d", &dos [j].second, &dos [j].first, &ocz [j].first); ocz [j].second = dos [j].second; } sort (dos, dos + dzi); sort (ocz, ocz + dzi); sum = 0; for (int j = 0; j < dzi; j++) { sum = sum + dos [j].second * dos [j].first; } for (int j = 0; j < dzi; j++) { sum = sum - ocz [j].second * ocz [j].first; } if (sum == 0 && dos [0].first <= ocz [0].first && dos [dzi - 1].first >= ocz [dzi - 1].first) { printf ("TAK\n"); } else { printf ("NIE\n"); } } return (0); } |