#include <cassert> #include <cstdint> #include <algorithm> #include <iostream> #include <string> #include <vector> #include <unordered_map> typedef int32_t i32; struct C { i32 c[2]; C() { c[0] = 0; c[1] = 0; } }; typedef std::unordered_map<i32, C> Map; int main() { i32 n; std::cin >> n; Map M; for (i32 i = 0; i < n; i++) { i32 r1, w, t; std::cin >> r1 >> w >> t; i32 k = w - t; M[k].c[r1 - 1]++; } i32 s = 0; for (const auto &p : M) { auto c = p.second.c; if (c[0] > 0 && c[1] > 0) s += std::min(c[0], c[1]); } std::cout << s << '\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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <cassert> #include <cstdint> #include <algorithm> #include <iostream> #include <string> #include <vector> #include <unordered_map> typedef int32_t i32; struct C { i32 c[2]; C() { c[0] = 0; c[1] = 0; } }; typedef std::unordered_map<i32, C> Map; int main() { i32 n; std::cin >> n; Map M; for (i32 i = 0; i < n; i++) { i32 r1, w, t; std::cin >> r1 >> w >> t; i32 k = w - t; M[k].c[r1 - 1]++; } i32 s = 0; for (const auto &p : M) { auto c = p.second.c; if (c[0] > 0 && c[1] > 0) s += std::min(c[0], c[1]); } std::cout << s << '\n'; return 0; } |