#include <cstdio> #include <map> using namespace std; int nextInt() { int n; scanf("%d", &n); return n; } int myMin(int a, int b) { return a < b ? a : b; } int main() { int n = nextInt(); map<int, int> cnt1, cnt2; for (int i=n-1; i>=0; --i) { int t = nextInt(); int s = nextInt(); s -= nextInt(); if (t == 1) ++cnt1[s]; if (t == 2) ++cnt2[s]; } int res = 0; for (map<int, int>::iterator it = cnt1.begin(); it != cnt1.end(); ++it) { int s = it->first; if (cnt2.count(s) == 0) continue; int a = it->second; int b = cnt2[s]; res += myMin(a, b); } printf("%d\n", res); 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 | #include <cstdio> #include <map> using namespace std; int nextInt() { int n; scanf("%d", &n); return n; } int myMin(int a, int b) { return a < b ? a : b; } int main() { int n = nextInt(); map<int, int> cnt1, cnt2; for (int i=n-1; i>=0; --i) { int t = nextInt(); int s = nextInt(); s -= nextInt(); if (t == 1) ++cnt1[s]; if (t == 2) ++cnt2[s]; } int res = 0; for (map<int, int>::iterator it = cnt1.begin(); it != cnt1.end(); ++it) { int s = it->first; if (cnt2.count(s) == 0) continue; int a = it->second; int b = cnt2[s]; res += myMin(a, b); } printf("%d\n", res); return 0; } |