#include <iostream>
int s1[2000001];
int s2[2000001];
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, a, w, t;
cin >> n;
for (int i=0; i<n; i++) {
cin >> a >> w >> t;
if (a==1) {
s1[w-t+1000000]++;
}
else {
s2[w-t+1000000]++;
}
}
int result = 0;
for (int i=0; i<2000001; i++) {
if (s1[i] > 0 && s2[i] > 0) {
result += min(s1[i], s2[i]);
}
}
cout <<result;
}
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 | #include <iostream> int s1[2000001]; int s2[2000001]; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, a, w, t; cin >> n; for (int i=0; i<n; i++) { cin >> a >> w >> t; if (a==1) { s1[w-t+1000000]++; } else { s2[w-t+1000000]++; } } int result = 0; for (int i=0; i<2000001; i++) { if (s1[i] > 0 && s2[i] > 0) { result += min(s1[i], s2[i]); } } cout <<result; } |
English