#include <iostream> #include <vector> #include <algorithm> #include <functional> using namespace std; int main() { ios_base::sync_with_stdio(0); int N; cin >> N; vector<int> diffs1(2000000, 0); vector<int> diffs2(2000000, 0); reference_wrapper<vector<int>> diffs[] = {ref(diffs1), ref(diffs2)}; for (int i = 0; i < N; i++) { int r, w, t; cin >> r >> w >> t; diffs[r-1].get()[1000000+t-w]++; } int s = 0; for (int i = 0; i < 2000000; i++) { s += min(diffs[0].get()[i], diffs[1].get()[i]); } cout << s << endl; 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 | #include <iostream> #include <vector> #include <algorithm> #include <functional> using namespace std; int main() { ios_base::sync_with_stdio(0); int N; cin >> N; vector<int> diffs1(2000000, 0); vector<int> diffs2(2000000, 0); reference_wrapper<vector<int>> diffs[] = {ref(diffs1), ref(diffs2)}; for (int i = 0; i < N; i++) { int r, w, t; cin >> r >> w >> t; diffs[r-1].get()[1000000+t-w]++; } int s = 0; for (int i = 0; i < 2000000; i++) { s += min(diffs[0].get()[i], diffs[1].get()[i]); } cout << s << endl; return 0; } |