#include<bits/stdc++.h>
using namespace std;
int32_t main(){
ios::sync_with_stdio(false);
int n;
cin >> n;
map<int,int> X,Y;
for(int i=0;i<n;i++) {
int v,x,t;
cin >> v >> x >> t;
if(v == 1)
Y[x-t]++;
else
X[x-t]++;
}
int res = 0;
for(auto kv:X)
res += min(kv.second,Y[kv.first]);
cout<<res<<"\n";
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<bits/stdc++.h> using namespace std; int32_t main(){ ios::sync_with_stdio(false); int n; cin >> n; map<int,int> X,Y; for(int i=0;i<n;i++) { int v,x,t; cin >> v >> x >> t; if(v == 1) Y[x-t]++; else X[x-t]++; } int res = 0; for(auto kv:X) res += min(kv.second,Y[kv.first]); cout<<res<<"\n"; } |
English