This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// trans rights
#include <bits/extc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int N;
int A[100005];
int B[100005];
int main(int argc, const char *argv[])
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
ll ans = 0;
for (int k = 0; k < 2 * N; k++)
{
int x, y;
cin >> x >> y;
int fx = min(N, max(1, x));
ans += abs(x - fx);
if (y <= 1)
{
A[fx]++;
ans += abs(y - 1);
}else
{
B[fx]++;
ans += abs(y - 2);
}
}
#ifdef DEBUG
cerr << ans << '\n';
#endif
for (int i = 1; i <= N; i++)
{
ans += abs(A[i - 1]) + abs(B[i - 1]);
A[i] += A[i - 1] - 1;
B[i] += B[i - 1] - 1;
int u = min(abs(A[i]), abs(B[i]));
if ((A[i] > 0) != (B[i] > 0))
{
if (A[i] > 0)
{
A[i] -= u;
B[i] += u;
}else{
A[i] += u;
B[i] -= u;
}
ans += u;
}
}
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... |