This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// 2021 A
#include <bits/stdc++.h>
#define pii pair<int,int>
#define loop(i,a,b) for(int i = a; i<b;i++)
using namespace std;
int arr[200005];
int b[200005];
//void db(){
// cout << "\n";
//}
//template<class T, class ...U>
//void db(T a, U ...b){
// cout << a << " "; db(b...);
//}
int main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
int n, i;
cin >> n;
for (i=1; i<=n; i++)
cin >> arr[i];
loop(i,1,n){
b[i] = arr[i+1] - arr[i];
}
int cnt = 0, tmp;
int l = 1, r = n-1;
while(l < r){
while(b[l] > 0 && l < r){
l++;
}
if(!(l < r)) break;
while(b[r] < 0 && l < r){
r--;
}
if(!(l < r)) break;
tmp = min(abs(b[l]), abs(b[r])) + 1;
b[l] += tmp; b[r] -= tmp;
cnt += tmp;
}
if(b[l] == 0) cnt++;
cout << cnt << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |