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>
using namespace std;
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pb emplace_back
const int N = 1e5 + 1;
int a[N][3];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
ll ans = 0;
for(int i = 0 ; i < n + n ; ++i) {
int x; cin >> x;
int y; cin >> 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]++;
}
int cnt1 = 0;
int cnt2 = 0;
for(int i = 1 ; i <= n ; ++i) {
cnt1 += a[i][1] - 1;
cnt2 += a[i][2] - 1;
if (cnt1 > 0 && cnt2 < 0) {
int x = min(cnt1,-cnt2); ans += x;
cnt1 -= x;
cnt2 += x;
}
if (cnt1 < 0 && cnt2 > 0) {
int x = min(cnt2,-cnt1); ans += x;
cnt1 += x;
cnt2 -= x;
}
ans += abs(cnt1);
ans += abs(cnt2);
}
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... |