#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int t;
cin >>t;
while (t--){
int n;
cin >>n;
vector <int> pocz (0);
vector <int> konc (0);
int l, a, b;
bool czy=true;
while (n--){
cin >>l >>a >>b;
while (l--){
pocz.push_back(a);
konc.push_back(b);
}
}
sort(pocz.begin(), pocz.end());
sort(konc.begin(), konc.end());
long long sumaa=0, sumab=0;
int dl=pocz.size();
for (int i=0; i<dl; i++){
sumaa+=pocz [i];
sumab+=konc [i];
}
if (sumaa!=sumab)
czy=false;
long long zapas=0;
for (int i=0; i<dl; i++){
zapas+=pocz[i];
zapas-=konc[i];
if (zapas>0)
czy=false;
}
for (int i=0; i<dl; i++){
zapas+=pocz[dl-i-1];
zapas-=konc[dl-i-1];
if (zapas<0)
czy=false;
}
if (czy)
cout <<"TAK";
else cout <<"NIE";
if (t!=0)
cout <<'\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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int t; cin >>t; while (t--){ int n; cin >>n; vector <int> pocz (0); vector <int> konc (0); int l, a, b; bool czy=true; while (n--){ cin >>l >>a >>b; while (l--){ pocz.push_back(a); konc.push_back(b); } } sort(pocz.begin(), pocz.end()); sort(konc.begin(), konc.end()); long long sumaa=0, sumab=0; int dl=pocz.size(); for (int i=0; i<dl; i++){ sumaa+=pocz [i]; sumab+=konc [i]; } if (sumaa!=sumab) czy=false; long long zapas=0; for (int i=0; i<dl; i++){ zapas+=pocz[i]; zapas-=konc[i]; if (zapas>0) czy=false; } for (int i=0; i<dl; i++){ zapas+=pocz[dl-i-1]; zapas-=konc[dl-i-1]; if (zapas<0) czy=false; } if (czy) cout <<"TAK"; else cout <<"NIE"; if (t!=0) cout <<'\n'; } return 0; } |
English