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 <map>
#include <iostream>
using namespace std;
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pl pair<ll,ll>
int main()
{
vi dis;
int n;
cin >> n;
int last;
cin >> last;
for (int i = 1; i < n; i++) {
int a;
cin >> a;
dis.push_back(a - last);
last = a;
}
ll s1 = 0;
ll s2 = 0;
for (int i = 0; i < n - 1; i++) {
if (dis[i] <= 0)
s1 -= dis[i]-1;
}
ll min = s1;
for (int i = n - 2; i >= 0; i--) {
if (dis[i] <= 0)
s1 += dis[i]-1;
else
s2 += dis[i]+1;
if (dis[i] == 0)
s2++;
if (min > max(s1, s2))
min = max(s1, s2);
}
cout << min;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |