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 n, i, j, ans, k;
int main(){
cin >> n;
long long a[n];
for(i=0; i<n; i++){
cin >> a[i];
if(i>0){
a[i-1]=a[i]-a[i-1];
}
}
i=0;
j=n-2;
while(i<j){
if(a[i]>0){
i++;
continue;
}
if(a[j]<0){
j--;
continue;
}
k=min(1-a[i], 1+a[j]);
a[i]+=k;
a[j]-=k;
ans+=k;
}
if(a[i]==0){
ans++;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |