#include <bits/stdc++.h>
#include <vector>
using namespace std;
int solve() {
int total;
cin >> total;
unordered_map<int, pair<int, int>> m;
for (int i=0; i<total; ++i) {
int type,pos,time;
cin >> type;
cin >> pos;
cin >> time;
int abs_pos = pos - time;
if (type == 1){
m[abs_pos].first += 1;
} else {
m[abs_pos].second += 1;
}
}
int ans = 0;
for (pair<int, pair<int, int>> kv: m) {
int abs_pos = kv.first;
int t1_count = kv.second.first;
int t2_count = kv.second.second;
ans += min(t1_count, t2_count);
}
cout << ans <<endl;
return 0;
}
int main() {
solve();
}
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 <bits/stdc++.h> #include <vector> using namespace std; int solve() { int total; cin >> total; unordered_map<int, pair<int, int>> m; for (int i=0; i<total; ++i) { int type,pos,time; cin >> type; cin >> pos; cin >> time; int abs_pos = pos - time; if (type == 1){ m[abs_pos].first += 1; } else { m[abs_pos].second += 1; } } int ans = 0; for (pair<int, pair<int, int>> kv: m) { int abs_pos = kv.first; int t1_count = kv.second.first; int t2_count = kv.second.second; ans += min(t1_count, t2_count); } cout << ans <<endl; return 0; } int main() { solve(); } |
English