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 <iostream>
#define ll long long
using namespace std;
int N, A[2][100001];
ll cost = 0;
int main()
{
ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N;
for (int i = 0; i < 2 * N; i++)
{
int x, y; cin >> x >> y; x--; y--;
if (y <= 0)
{
cost += -y;
if (x <= 0) {A[0][0]++; cost += -x;}
else if (x < N) {A[0][x]++;}
else {A[0][N - 1]++; cost += x - N + 1;}
}
else
{
cost += y - 1;
if (x <= 0) {A[1][0]++; cost += -x;}
else if (x < N) {A[1][x]++;}
else {A[1][N - 1]++; cost += x - N + 1;}
}
}
int a = 0, b = 0;
for (int i = 0; i < N; i++)
{
a += A[0][i] - 1; b += A[1][i] - 1;
//cerr << a << " " << b << "\n";
while (a > 0 && b < 0) {a--; b++; cost++;}
while (a < 0 && b > 0) {a++; b--; cost++;}
cost += abs(a) + abs(b);
}
cout << cost << "\n";
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... |