| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1327986 | vtnoo | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 0 ms | 332 KiB |
#include <bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define all(x) x.begin(), x.end()
#define sz(a) ((int) a.size())
#define pb push_back
#define fst first
#define snd second
using namespace std;
typedef long long ll;
const int MAXN=2e5+5,INF=1e18;
ll a[MAXN];
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;cin>>n;
L(i,0,n-1)cin>>a[i];
vector<ll>b(n-1);
L(i,1,n-1){
b[i-1]+=a[i]-a[i-1];
}
vector<ll>pref(n),suff(n);
L(i,0,n-2){
pref[i+1]=pref[i];
if(b[i]<=0)pref[i+1]+=1ll+-1ll*b[i];
}
R(i,n-2,0){
suff[i]=suff[i+1];
if(b[i]>=0)suff[i]+=b[i]+1ll;
}
ll ans=INF;
L(i,0,n-1){
ans=min(ans,max(pref[i],suff[i]));
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
