#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, r, w, t;
cin >> n;
unordered_map<int, int> m[2];
for(int i = 0; i < n; i++) {
cin >> r >> w >> t;
r--;
m[r][w - t]++;
}
int res = 0;
for(auto v : m[0]) {
res += min(v.second, m[1][v.first]);
}
for(auto v : m[1]) {
res += min(v.second, m[0][v.first]);
}
res /= 2;
cout << res;
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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, r, w, t; cin >> n; unordered_map<int, int> m[2]; for(int i = 0; i < n; i++) { cin >> r >> w >> t; r--; m[r][w - t]++; } int res = 0; for(auto v : m[0]) { res += min(v.second, m[1][v.first]); } for(auto v : m[1]) { res += min(v.second, m[0][v.first]); } res /= 2; cout << res; return 0; } |
English