#include <iostream> #include <unordered_map> int main() { std::ios_base::sync_with_stdio(0); int n; std::cin >> n; std::unordered_map<int, int> R[2]; for (int i=0;i<n;++i) { int r,w,t; std::cin >> r >> w >> t; R[r-1][t-w]++; } int result = 0; for (const auto& x : R[0]) result += std::min(x.second, R[1][x.first]); std::cout << result << std::endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream> #include <unordered_map> int main() { std::ios_base::sync_with_stdio(0); int n; std::cin >> n; std::unordered_map<int, int> R[2]; for (int i=0;i<n;++i) { int r,w,t; std::cin >> r >> w >> t; R[r-1][t-w]++; } int result = 0; for (const auto& x : R[0]) result += std::min(x.second, R[1][x.first]); std::cout << result << std::endl; return 0; } |