#include <iostream>
#include <map>
#include <algorithm>
int main() {
int n;
std::cin >> n;
std::map<int, int> A, B;
for (int i = 0; i < n; i++) {
int r, w, t;
std::cin >> r >> w >> t;
if (r == 1) {
A[w - t]++;
} else {
B[w - t]++;
}
}
int result = 0;
for (const auto &[k,v]: A) {
result += std::min(v, B[k]);
}
std::cout << result << '\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 | #include <iostream> #include <map> #include <algorithm> int main() { int n; std::cin >> n; std::map<int, int> A, B; for (int i = 0; i < n; i++) { int r, w, t; std::cin >> r >> w >> t; if (r == 1) { A[w - t]++; } else { B[w - t]++; } } int result = 0; for (const auto &[k,v]: A) { result += std::min(v, B[k]); } std::cout << result << '\n'; return 0; } |
English