This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1e5 + 5;
ll ans;
int n, x, y, a[N][5], x1, x2, change;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1, x, y; i <= n * 2; ++i){
cin >> x >> y;
if(x > n) {ans += x - n; x = n;}
if(x < 1) {ans += 1 - x; x = 1;}
if(y > 2) {ans += y - 2; y = 2;}
if(y < 1) {ans += 1 - y; y = 1;}
a[x][y]++;
}
for(int i = 1; i <= n; ++i){
x1 += a[i][1];
x2 += a[i][2];
x1--;
x2--;
if((x1 > 0 && x2 < 0) || (x1 < 0 && x2 > 0)){
change = min(abs(x1), abs(x2));
ans += change;
if(x1 < 0) x1 += change;
else x1 -= change;
if(x2 < 0) x2 += change;
else x2 -= change;
}
ans += abs(x1) + abs(x2);
}
cout << ans;
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... |