Submission #778755

#TimeUsernameProblemLanguageResultExecution timeMemory
778755DobromirAngelovCoin Collecting (JOI19_ho_t4)C++14
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int MAXN=1e5+5; int n; int cnt[2][MAXN]; long long ans=0; void add(int t,int x) { if(x<1) { ans+=1-x; cnt[t][1]++; } else if(x>n) { ans+=x-n; cnt[t][n]++; } else cnt[t][x]++; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=1; i<=2*n; i++) { int x,y; cin>>x>>y; if(y<=1) { add(0,x); ans+=1-y; } else { add(1,x); ans+=y-2; } } int r0=0,r1=0; for(int i=1; i<=n; i++) { r0+=cnt[0][i]; r1+=cnt[1][i]; /*int vert=0; if(r0<i && i<r1) { vert=min(i-r0, r1-i); r0+=vert; r1-=vert; } if(r0>i && i>r1) { vert=min(r0-i, i-r1); r0-=vert; r1+=vert; } ans+=vert;*/ ans+=abs(r0+r1-2*i); } ans+=abs(r0-n); cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...