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>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define sp " "
#define endl "\n"
#define mod 1000000007
#define MAXN 200005
#define MAXM 1000005
#define inf 1e18
#define INF 0x3f
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) for(auto& a: x) cout << a << " "
using namespace std;
typedef long long int lo;
lo arr[MAXN],dad[MAXN],sz[MAXN];
lo n,m,k;
vector<pair<lo,lo>> v[505];
string s;
void solve() {
cin >> n;
lo mx=0, mxind=0;
for (int i = 0; i < n; ++i)
{
cin >> arr[i];
if(mx <= arr[i]){
mxind = i;
mx = arr[i];
}
}
vector<lo> duz(n+1,0);
vector<lo> ters(n+1,0);
for (int i = 1; i < n; ++i)
{
if(arr[i] <= arr[i-1]+duz[i-1]){
duz[i] = arr[i-1]-arr[i]+duz[i-1]+1;
}
}
for (int i = n-2; i >= 0; i--)
{
if(arr[i] <= arr[i+1]+ters[i+1]){
ters[i] = arr[i+1]-arr[i]+ters[i+1]+1;
}
}
// debug(duz);
// cout << endl;
// debug(ters);
// cout << endl;
lo ans = inf;
for (int i = 0; i < n; ++i)
{
// cout << "1: " << i << sp << ans << endl;
if(i == 0){
// cout << ters[i] << endl;
ans = min(ans,ters[i]);
// cout<< "2: " << i << sp << ans << endl;
continue;
}
ans = min(ans,max(ters[i],duz[i]));
}
cout << ans << endl;
}
int main()
{
// cout << fixed << setprecision(12);
// freopen("snowboots.in","r",stdin);
// freopen("snowboots.out","w",stdout);
fast;
int t = 1;
// cin >> t;
while(t--)
{
solve();
}
// cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:27:14: warning: variable 'mxind' set but not used [-Wunused-but-set-variable]
27 | lo mx=0, mxind=0;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |