#include <iostream> #include <vector> #include <map> int main() { int n; std::cin >> n; int maxT = 0; int result = 0; std::vector<std::pair<int, int> > firstType, secondType; std::map<int, int> firstTypeMap, secondTypeMap; for (int i = 0; i < n; i++) { int r, w, t; std::cin >> r >> w >> t; if (t > maxT) { maxT = t; } if (r == 1) { firstType.emplace_back(w, t); } else { secondType.emplace_back(w, t); } } for (auto p : firstType) { firstTypeMap[p.first - p.second - maxT]++; } for (auto p : secondType) { secondTypeMap[p.first - p.second - maxT]++; } for (const auto &p : firstTypeMap) { if (secondTypeMap[p.first] > 0) { result += std::min(p.second, secondTypeMap[p.first]); } } std::cout << result; 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 | #include <iostream> #include <vector> #include <map> int main() { int n; std::cin >> n; int maxT = 0; int result = 0; std::vector<std::pair<int, int> > firstType, secondType; std::map<int, int> firstTypeMap, secondTypeMap; for (int i = 0; i < n; i++) { int r, w, t; std::cin >> r >> w >> t; if (t > maxT) { maxT = t; } if (r == 1) { firstType.emplace_back(w, t); } else { secondType.emplace_back(w, t); } } for (auto p : firstType) { firstTypeMap[p.first - p.second - maxT]++; } for (auto p : secondType) { secondTypeMap[p.first - p.second - maxT]++; } for (const auto &p : firstTypeMap) { if (secondTypeMap[p.first] > 0) { result += std::min(p.second, secondTypeMap[p.first]); } } std::cout << result; return 0; } |