#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
//HEURA
int totrzym[100010];
int pojemnosc[100010];
int toczek[100010];
int testow;
int ile;
pair <int, int> t1[100010];
pair <int, int> t2[100010];
unsigned long long a, b;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> testow;
for(int test = 0; test < testow; test++){
cin >> ile;
a = 0;
b = 0;
for(int i = 0; i < ile; i++){
cin >> pojemnosc[i] >> totrzym[i] >> toczek[i];
totrzym[i] = -totrzym[i];
toczek[i] = -toczek[i];
t1[i].first = totrzym[i];
t1[i].second = totrzym[i] * pojemnosc[i];
t2[i].first = toczek[i];
t2[i].second = totrzym[i] * toczek[i];
if(toczek[i] == totrzym[i]){
i--;
ile--;
//nie potrzebujemy tego elementu
}
}
for(int i = 0; i < ile; i++){
a += abs(pojemnosc[i] * totrzym[i]);
b += abs(pojemnosc[i] * toczek[i]);
}
if(a != b){
cout << "NIE\n";
continue;
}
string wynik = "NIE\n";
//sprawdzamy czy najcieplejsza z a jest wieksza od najcieplejszej z b
sort(t1, t1+ile);
sort(t2, t2+ile);
/*
for(int i=0;i<ile;i++){
cout<<t1[i].first<<" ";
}cout<<endl;
for(int i=0;i<ile;i++){
cout<<t2[i].first<<" ";
}cout<<endl;*/
int licz = 0;
while(licz < ile){
if(t1[licz].first < t2[licz].first){
wynik = "TAK\n";
}
else if(t1[licz].first == t2[licz].first){
if(t1[licz].second < t2[licz].second){
wynik = "TAK\n";
}
else{
break;
}
}
else{
break;
}
licz++;
}
cout << wynik;
}
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include <iostream> #include <algorithm> #include <utility> using namespace std; //HEURA int totrzym[100010]; int pojemnosc[100010]; int toczek[100010]; int testow; int ile; pair <int, int> t1[100010]; pair <int, int> t2[100010]; unsigned long long a, b; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> testow; for(int test = 0; test < testow; test++){ cin >> ile; a = 0; b = 0; for(int i = 0; i < ile; i++){ cin >> pojemnosc[i] >> totrzym[i] >> toczek[i]; totrzym[i] = -totrzym[i]; toczek[i] = -toczek[i]; t1[i].first = totrzym[i]; t1[i].second = totrzym[i] * pojemnosc[i]; t2[i].first = toczek[i]; t2[i].second = totrzym[i] * toczek[i]; if(toczek[i] == totrzym[i]){ i--; ile--; //nie potrzebujemy tego elementu } } for(int i = 0; i < ile; i++){ a += abs(pojemnosc[i] * totrzym[i]); b += abs(pojemnosc[i] * toczek[i]); } if(a != b){ cout << "NIE\n"; continue; } string wynik = "NIE\n"; //sprawdzamy czy najcieplejsza z a jest wieksza od najcieplejszej z b sort(t1, t1+ile); sort(t2, t2+ile); /* for(int i=0;i<ile;i++){ cout<<t1[i].first<<" "; }cout<<endl; for(int i=0;i<ile;i++){ cout<<t2[i].first<<" "; }cout<<endl;*/ int licz = 0; while(licz < ile){ if(t1[licz].first < t2[licz].first){ wynik = "TAK\n"; } else if(t1[licz].first == t2[licz].first){ if(t1[licz].second < t2[licz].second){ wynik = "TAK\n"; } else{ break; } } else{ break; } licz++; } cout << wynik; } return 0; } |
English