#include "bits/stdc++.h"
using namespace std;
#define int long long
const int N = 1e5 + 10;
int x[2 * N], y[2 * N];
int f[N][3];
int ans = 0;
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> v;
for (int i = 1; i <= 2 * n; i++) {
cin >> x[i] >> y[i];
if (x[i] < 1) {
ans += 1 - x[i];
x[i] = 1;
}
if (x[i] > n) {
ans += x[i] - n;
x[i] = n;
}
if (y[i] < 1) {
ans += 1 - y[i];
y[i] = 1;
}
if (y[i] > 2) {
ans += y[i] - 2;
y[i] = 2;
}
f[x[i]][y[i]]++;
}
int a = 0, b = 0;
for (int i = 1; i <= n; i++) {
a += f[i][1] - 1;
b += f[i][2] - 1;
while (a < 0 && b > 0) a++, b--, ans++;
while (a > 0 && b < 0) a--, b++, ans++;
ans += abs(a) + abs(b);
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |