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;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
const int LIM=1e5+7;
const ll INF=1e18+7;
ll ile[LIM][2];
vector<pair<ll,ll>>V;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
ll n;
cin >> n;
ll ans=0;
rep(i, 2*n) {
ll a, b;
cin >> a >> b;
ans+=max(1-a, 0ll);
a=max(a, 1ll);
ans+=max(a-n, 0ll);
a=min(a, n);
ans+=max(1-b, 0ll);
b=max(b, 1ll);
ans+=max(b-2, 0ll);
b=min(b, 2ll);
--a; --b;
++ile[a][b];
}
rep(i, n) {
--ile[i][0]; --ile[i][1];
if(ile[i][0]<0 && ile[i][1]>0) {
ll p=min(abs(ile[i][0]), ile[i][1]);
ans+=p;
ile[i][0]+=p;
ile[i][1]-=p;
}
if(ile[i][0]>0 && ile[i][1]<0) {
ll p=min(abs(ile[i][1]), ile[i][0]);
ans+=p;
ile[i][0]-=p;
ile[i][1]+=p;
}
ans+=abs(ile[i][0]);
ans+=abs(ile[i][1]);
ile[i+1][0]+=ile[i][0];
ile[i+1][1]+=ile[i][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... |