#include <iostream> #include <vector> #include <algorithm> struct cup { int l, a, b; }; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); int t; std::cin >> t; for (int i = 0; i < t; i++) { int n; std::cin >> n; std::vector<cup> tab(n); long long volumeSum = 0; long long startTempSum = 0; long long endTempSum = 0; int limitsOrig[2] = {0,0}; //0 min 1 max int limitsEnd[2] = {0,0}; for (int j = 0; j < n; j++) { std::cin >> tab[j].l >> tab[j].a >> tab[j].b; volumeSum += tab[j].l; startTempSum += (long long)tab[j].l * (long long)tab[j].a; endTempSum += (long long)tab[j].l * (long long)tab[j].b; if (j == 0) { limitsOrig[0] = tab[0].a; limitsOrig[1] = tab[0].a; limitsEnd[0] = tab[0].b; limitsEnd[1] = tab[0].b; } else { if (limitsOrig[0] > tab[j].a) limitsOrig[0] = tab[j].a; if (limitsOrig[1] < tab[j].a) limitsOrig[1] = tab[j].a; if (limitsEnd[0] > tab[j].b) limitsEnd[0] = tab[j].b; if (limitsEnd[1] < tab[j].b) limitsEnd[1] = tab[j].b; } } if (startTempSum == endTempSum && limitsEnd[0] >= limitsOrig[0] && limitsEnd[1] <= limitsOrig[1]) std::cout << "TAK\n"; else std::cout << "NIE\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 | #include <iostream> #include <vector> #include <algorithm> struct cup { int l, a, b; }; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); int t; std::cin >> t; for (int i = 0; i < t; i++) { int n; std::cin >> n; std::vector<cup> tab(n); long long volumeSum = 0; long long startTempSum = 0; long long endTempSum = 0; int limitsOrig[2] = {0,0}; //0 min 1 max int limitsEnd[2] = {0,0}; for (int j = 0; j < n; j++) { std::cin >> tab[j].l >> tab[j].a >> tab[j].b; volumeSum += tab[j].l; startTempSum += (long long)tab[j].l * (long long)tab[j].a; endTempSum += (long long)tab[j].l * (long long)tab[j].b; if (j == 0) { limitsOrig[0] = tab[0].a; limitsOrig[1] = tab[0].a; limitsEnd[0] = tab[0].b; limitsEnd[1] = tab[0].b; } else { if (limitsOrig[0] > tab[j].a) limitsOrig[0] = tab[j].a; if (limitsOrig[1] < tab[j].a) limitsOrig[1] = tab[j].a; if (limitsEnd[0] > tab[j].b) limitsEnd[0] = tab[j].b; if (limitsEnd[1] < tab[j].b) limitsEnd[1] = tab[j].b; } } if (startTempSum == endTempSum && limitsEnd[0] >= limitsOrig[0] && limitsEnd[1] <= limitsOrig[1]) std::cout << "TAK\n"; else std::cout << "NIE\n"; } } |