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;
long long a[100005][3], b[3];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, ans=0;
cin >> n;
for (long long i=1; i<=n*2; i++)
{
long long x, y;
cin >> x >> y;
if (x<1)
ans+=1-x, x=1;
if (x>n)
ans+=x-n, x=n;
if (y<1)
ans+=1-y, y=1;
if (y>2)
ans+=y-2, y=2;
a[x][y]++;
}
for (long long i=1; i<=n; i++)
{
b[1]+=a[i][1]-1;
b[2]+=a[i][2]-1;
if (b[1]>0 && b[2]<0)
{
long long mn=min(b[1], -b[2]);
ans+=mn, b[1]-=mn, b[2]+=mn;
}
else if (b[1]<0 && b[2]>0)
{
long long mn=min(-b[1], b[2]);
ans+=mn, b[1]+=mn, b[2]-=mn;
}
ans+=abs(b[1])+abs(b[2]);
}
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... |