#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MXN = 1e5+5;
int n, a[MXN], up, dw;
ll ans;
int32_t main() {
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
cin >> n;
for(int i=1,x,y; i<=2*n; i++) {
cin >> x >> y;
if(y>=2) {
up++;
ans += y-2;
}
else {
dw++;
ans += 1-y;
}
if(x<1) {
ans += 1-x;
x = 1;
}
else if(x>n) {
ans += x-n;
x = n;
}
a[x]++;
}
ans += abs(up-dw)>>1;
for(int i=1; i<=n; i++)
ans += abs(a[i] += a[i-1]-2);
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |