#include <iostream>
using namespace std;
long long n, x, y, xx, yy, a[100010][3], ans, c[100010], b[3];
int main() {
cin >> n;
for (int i = 1; i <= 2*n; i++) {
cin >> x >> y;
if (y <= 1) yy = 1;
else yy = 2;
if (x < 1) xx = 1;
else if (x > n) xx = n;
else xx = x;
a[xx][yy]++;
ans += abs(x-xx)+abs(y-yy);
}
x = y = 0;
for (int i = 1; i <= n; i++) {
x += a[i][1]-1;
y += a[i][2]-1;
while (x < 0 && y > 0) x++, y--, ans++;
while (x > 0 && y < 0) x--, y++, ans++;
ans += abs(x)+abs(y);
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |