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;
using ll = long long;
int n, x[200200], y[200200], c[100100][2];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=1;i<=n+n;i++) cin >> x[i] >> y[i];
ll ans = 0;
for(int i=1;i<=n+n;i++) {
int D = min(max(x[i], 1), n);
ans += abs(D-x[i]);
if(y[i] >= 2) {
c[D][0]++;
ans += y[i]-2;
} else {
c[D][1]++;
ans += 1-y[i];
}
}
for(int i=1;i<=n;i++) {
c[i][0] += c[i-1][0]-1;
c[i][1] += c[i-1][1]-1;
if(c[i][0] > 0 && c[i][1] < 0) c[i][0]--, c[i][1]++, ans++;
if(c[i][1] > 0 && c[i][0] < 0) c[i][1]--, c[i][0]++, ans++;
ans += abs(c[i][0]) + abs(c[i][1]);
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |