#include <bits/stdc++.h>
using namespace std;
const long long MILION = 1e6 + 123;
const long long N_MAX = 5e5 + 123;
long long n, r, w, t;
long long t1[N_MAX]; long long t2[N_MAX];
long long minus_t1[N_MAX]; long long minus_t2[N_MAX];
long long res;
int main(){
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i){
cin >> r >> w >> t;
if (w - t >= 0){
if (r == 1){
t1[w - t]++;
}
else {
t2[w - t]++;
}
}
else {
if (r == 1){
minus_t1[abs(w - t)]++;
}
else {
minus_t2[abs(w - t)]++;
}
}
}
for (long long i = 0; i <= MILION; ++i){
if (t1[i] != 0 && t2[i] != 0){
if (t1[i] < t2[i]){
res += t1[i];
}
else {
res += t2[i];
}
}
}
/*for (int i = 0; i <= n; ++i){
cout << t1[i] << " ";
}
cout << '\n';
for (int i = 0; i <= n; ++i){
cout << t2[i] << " ";
}
cout << '\n';
for (int i = 0; i <= n; ++i){
cout << minus_t1[i] << " ";
}
cout << '\n';
for (int i = 0; i <= n; ++i){
cout << minus_t2[i] << " ";
}
cout << '\n';*/
for (long long i = 0; i <= MILION; ++i){
if (minus_t1[i] != 0 && minus_t2[i] != 0){
if (minus_t1[i] < minus_t2[i]){
res += minus_t1[i];
}
else {
res += minus_t2[i];
}
}
}
cout << res << '\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 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 | #include <bits/stdc++.h> using namespace std; const long long MILION = 1e6 + 123; const long long N_MAX = 5e5 + 123; long long n, r, w, t; long long t1[N_MAX]; long long t2[N_MAX]; long long minus_t1[N_MAX]; long long minus_t2[N_MAX]; long long res; int main(){ ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i){ cin >> r >> w >> t; if (w - t >= 0){ if (r == 1){ t1[w - t]++; } else { t2[w - t]++; } } else { if (r == 1){ minus_t1[abs(w - t)]++; } else { minus_t2[abs(w - t)]++; } } } for (long long i = 0; i <= MILION; ++i){ if (t1[i] != 0 && t2[i] != 0){ if (t1[i] < t2[i]){ res += t1[i]; } else { res += t2[i]; } } } /*for (int i = 0; i <= n; ++i){ cout << t1[i] << " "; } cout << '\n'; for (int i = 0; i <= n; ++i){ cout << t2[i] << " "; } cout << '\n'; for (int i = 0; i <= n; ++i){ cout << minus_t1[i] << " "; } cout << '\n'; for (int i = 0; i <= n; ++i){ cout << minus_t2[i] << " "; } cout << '\n';*/ for (long long i = 0; i <= MILION; ++i){ if (minus_t1[i] != 0 && minus_t2[i] != 0){ if (minus_t1[i] < minus_t2[i]){ res += minus_t1[i]; } else { res += minus_t2[i]; } } } cout << res << '\n'; return 0; } |
English