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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e5 + 5;
int n;
int cnt[N][2];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
long long res = 0;
for (int i = 0; i < 2 * n; ++i) {
int x, y; cin >> x >> y;
if (x > n) {
res += x - n;
x = n;
} else if (x < 1) {
res += 1 - x;
x = 1;
}
if (y < 2) {
res += 1 - y;
y = 1;
} else {
res += y - 2;
y = 2;
}
assert(1 <= x && x <= n && 1 <= y && y <= 2);
++cnt[x][--y];
}
int a = 0, b = 0;
for (int i = 1; i <= n; ++i) {
a += cnt[i][0] - 1, b += cnt[i][1] - 1;
while (a > 0 && b < 0) {
a--, b++, res++;
}
while (a < 0 && b > 0) {
a++, b--, res++;
}
res += abs(a) + abs(b);
}
cout << res;
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... |