#include <cstdio> #include <vector> #include <algorithm> #include <iostream> #include <map> using namespace std; #define f first #define s second const int MAXN = 2e6 + 3; const int INF = 1e6; pair<int, int> t[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; int c, x, k; cin >> n; for (int i = 1; i <= n; i++) { cin >> c >> x >> k; if (c == 1) t[x - k + INF].f++; else t[x - k + INF].s++; } int ans = 0; for (int i = 0; i < MAXN; i++) ans += min(t[i].f, t[i].s); cout << ans; 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 <cstdio> #include <vector> #include <algorithm> #include <iostream> #include <map> using namespace std; #define f first #define s second const int MAXN = 2e6 + 3; const int INF = 1e6; pair<int, int> t[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; int c, x, k; cin >> n; for (int i = 1; i <= n; i++) { cin >> c >> x >> k; if (c == 1) t[x - k + INF].f++; else t[x - k + INF].s++; } int ans = 0; for (int i = 0; i < MAXN; i++) ans += min(t[i].f, t[i].s); cout << ans; return 0; } |