#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <climits> using namespace std; void input(int &n, unordered_map<int, int> &m1, unordered_map<int, int> &m2) { int r, w, t; cin >> n; for (int i = 0; i < n; i++) { cin >> r >> w >> t; if (r == 1) m1[w - t]++; else m2[w - t]++; } } int solve(int &n, unordered_map<int, int> &m1, unordered_map<int, int> &m2) { int result = 0; for (auto [key, val] : m1) if (m2[key] > 0) result += min(val, m2[key]); return result; } int main() { ios_base::sync_with_stdio(0); int n; unordered_map<int, int> m1, m2; input(n, m1, m2); cout << solve(n, m1, m2) << "\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 | #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <climits> using namespace std; void input(int &n, unordered_map<int, int> &m1, unordered_map<int, int> &m2) { int r, w, t; cin >> n; for (int i = 0; i < n; i++) { cin >> r >> w >> t; if (r == 1) m1[w - t]++; else m2[w - t]++; } } int solve(int &n, unordered_map<int, int> &m1, unordered_map<int, int> &m2) { int result = 0; for (auto [key, val] : m1) if (m2[key] > 0) result += min(val, m2[key]); return result; } int main() { ios_base::sync_with_stdio(0); int n; unordered_map<int, int> m1, m2; input(n, m1, m2); cout << solve(n, m1, m2) << "\n"; return 0; } |