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;
const int MAXN = 200005;
int n;
long long ans, cnt;
long long X[MAXN], Y[MAXN];
vector <long long> V;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1; i <= 2 * n; i++)
{
cin >> X[i] >> Y[i];
if(X[i] <= 0)
{
ans += (1 - X[i]);
X[i] = 1;
}
if(X[i] > n)
{
ans += (X[i] - n);
X[i] = n;
}
if(X[i] >= 1 and X[i] <= n)
{
if(Y[i] <= 1)
{
ans -= (Y[i] - 1);
cnt++;
}
else
{
ans += (Y[i] - 2);
}
V.push_back(X[i]);
}
}
sort(V.begin(), V.end());
ans += abs(cnt - n);
for(int i = 0; i < (int)V.size(); i += 2)
{
ans += abs(V[i] - i / 2 - 1);
ans += abs(V[i + 1] - i / 2 - 1);
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |