#include <cstdio> #include <cstdlib> #include <map> int main() { int n; scanf("%d", &n); struct trucks { int count[2] = { 0, 0 }; }; std::map<int, trucks> counts; while (n --> 0) { int typ, coord, tim; scanf("%d %d %d", &typ, &coord, &tim); counts[coord - tim].count[typ-1]++; } int recall_count = 0; for (const auto& p : counts) { recall_count += std::min(p.second.count[0], p.second.count[1]); } printf("%d\n", recall_count); 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 | #include <cstdio> #include <cstdlib> #include <map> int main() { int n; scanf("%d", &n); struct trucks { int count[2] = { 0, 0 }; }; std::map<int, trucks> counts; while (n --> 0) { int typ, coord, tim; scanf("%d %d %d", &typ, &coord, &tim); counts[coord - tim].count[typ-1]++; } int recall_count = 0; for (const auto& p : counts) { recall_count += std::min(p.second.count[0], p.second.count[1]); } printf("%d\n", recall_count); return 0; } |