#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e6 + 5;
const int oo = 1e9, mod = 1e9 + 7;
int n, k, x, y, a, b, ans=0;
int m[N][3];
void process() {
cin >> n;
foru(i,1,n*2) {
int x, y; cin >> x >> y;
if (x<1) ans+=1-x, x=1;
else if (x>n) ans+=x-n, x=n;
if (y<1) ans+=1-y, y=1;
else if (y>2) ans+=y-2, y=2;
m[x][y]++;
}
foru(i,1,n) {
a+=m[i][1]-1, b+=m[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;
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI
Flow:
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
500 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
500 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
500 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |