#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve() {
int n;
cin >> n;
vector <int> x(2 * n + 1), y(2 * n + 1), pref(2 * n + 1), cnt(3);
int ans = 0;
for(int i = 1; i <= 2 * n; i++) {
cin >> x[i] >> y[i];
if(1 <= x[i] && x[i] <= n) {
if(y[i] >= 2) {
ans += y[i] - 2;
y[i] = 2;
}
else{
ans += 1 - y[i];
y[i] = 1;
}
}
else{
if(y[i] >= 2) {
ans += y[i] - 2;
y[i] = 2;
}
else{
ans += 1 - y[i];
y[i] = 1;
}
if(x[i] >= n) {
ans += x[i] - n;
x[i] = n;
}
else{
ans += 1 - x[i];
x[i] = 1;
}
}
cnt[y[i]]++;
pref[x[i]]++;
}
for(int i = 1; i <= n; i++) {
pref[i] += pref[i - 1];
}
ans += n - min(cnt[1], cnt[2]);
for(int i = 1; i <= n; i++) {
ans += abs( (2 * i) - pref[i] );
}
cout << ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt--) {
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |