#include <bits/stdc++.h>
using namespace std;
int tabi[1000001], tabj[1000001];
int utabi[1000001], utabj[1000001];
int main(){
ios_base::sync_with_stdio();
cin.tie();
cout.tie();
int n; cin >> n;
for(int i=0; i<n; i++){
int t,a,b; cin >> a >> b >> t;
int x = b - t;
if(a == 1){
if(x >= 0){
tabi[x]++;
}
else{
x *= -1;
utabi[x]++;
}
}
if(a == 2){
if(x >= 0){
tabj[x]++;
}
else{
x *= -1;
utabj[x]++;
}
}
}
long long res = 0;
for(int i=0; i<=1000000; i++){
res += min(tabi[i], tabj[i]);
res += min(utabi[i], utabj[i]);
}
cout << res << "\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 | #include <bits/stdc++.h> using namespace std; int tabi[1000001], tabj[1000001]; int utabi[1000001], utabj[1000001]; int main(){ ios_base::sync_with_stdio(); cin.tie(); cout.tie(); int n; cin >> n; for(int i=0; i<n; i++){ int t,a,b; cin >> a >> b >> t; int x = b - t; if(a == 1){ if(x >= 0){ tabi[x]++; } else{ x *= -1; utabi[x]++; } } if(a == 2){ if(x >= 0){ tabj[x]++; } else{ x *= -1; utabj[x]++; } } } long long res = 0; for(int i=0; i<=1000000; i++){ res += min(tabi[i], tabj[i]); res += min(utabi[i], utabj[i]); } cout << res << "\n"; } |
English