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>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace std;
#define LL long long
#define pLL pair<long long, long long>
#define F first
#define S second
#define pb push_back
#define rz resize
#define all(x) x.begin(), x.end()
//#define cin fin
void Star_Brust_Stream()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
return;
}
const LL INF = 1e18;
const LL MOD = 1e9 + 7;
int main()
{
Star_Brust_Stream();
LL n;
cin >> n;
vector<LL> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i];
}
LL l = 0, r = n - 1;
LL cnt = 0;
while (l < r)
{
while (v[l] < v[l + 1])
{
l++;
}
while (v[r - 1] > v[r])
{
r--;
}
cnt += min(v[l] - v[l + 1], v[r] - v[r - 1]) + 1;
l++;
r--;
}
cout << cnt << endl;
// system("pause");
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |