이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mikumywaifu ios_base::sync_with_stdio(0)
#define mudrockmywaifu cin.tie(0)
#define pb push_back
#define ss second
#define ff first
#define mem(i,j) memset(i,j,sizeof(i))
#define pii pair<int,int>
#define pll pair<long,long>
#define lowbit(x) x&-x
const int INF =0x3F3F3F3F;
const ll LINF=4611686018426387903;
ll gcd(ll a,ll b){
if(b==0) return a;
a%=b;
return gcd(b,a);
}
void debug(){
cout<<"DEBUG :";
cout<<"\n";
}
/*-----------------------------------------*/
signed main(){
mikumywaifu;
mudrockmywaifu;
int n;
cin>>n;
vector<ll>a(n+1),b(n+1);
for(int i=0;i<n;i++){
cin>>a[i];
b[i]=a[i];
}
vector<ll> l(n+1),r(n+1);
l[0]=0,r[n-1]=0;
for(int i=1;i<n;i++){
l[i]=l[i-1];
l[i]+=(a[i]>a[i-1])?0:a[i-1]-a[i]+1;
}
for(int i=n-2;i>=0;i--){
r[i]=r[i+1];
r[i]+=(b[i]>b[i+1])?0:b[i+1]-b[i]+1;
}
ll ans=1e18;
for(int i=0;i<n;i++){
ans=min(ans,max(l[i],r[i]));
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |