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;
#define int long long
const int maxn=2e5 + 5;
const int mod=1e9+7;
int kol[100001][2];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,x,y;
cin>>n;
long long ans=0;
for(int i=1;i<=n;i++)
{
kol[i][0]=0;
kol[i][1]=0;
}
for(int i=0;i<2*n;i++)
{
cin>>x>>y;
if(x<1)
{
ans+=1-x;
x=1;
}
else if(x>n)
{
ans+=x-n;
x=n;
}
if(y<1)
{
ans+=1-y;
y=1;
}
else if(y>2)
{
ans+=y-2;
y=2;
}
kol[x][y-1]++;
}
int a=0,b=0;
for(int i=1;i<=n;i++)
{
a+=kol[i][0];
b+=kol[i][1];
if(a>i && b<i)
{
int c=min(a-i,i-b);
ans+=c;
a-=c;
b+=c;
}
else if(a<i && b>i)
{
int c=min(b-i,i-a);
ans+=c;
a+=c;
b-=c;
}
ans+=abs(a-i);
ans+=abs(b-i);
}
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... |