# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
901391 | nxteru | Ancient Books (IOI17_books) | C++14 | 0 ms | 0 KiB |
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;
using ll =long long;
int p[10000005];
int main(void){
int n,s;
cin>>n>>s;
ll ans=0;
int ma=0;
for(int i=0;i<n;i++){
cin>>p[i];
ans+=abs(p[i]-i);
ma=max(ma,p[i]);
if(ma<=i&&i<n-1)ans+=2;
}
cout<<ans<<endl;
}