# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1226340 | lamlamlam | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 23 ms | 4936 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define task "sus"
const int MN = 2e5+5,inf = 1e18;
int n,a[MN],l[MN],r[MN];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n;
for(int i=1; i<=n; i++) cin >> a[i];
int cur = 0,ans = inf;
for(int i=1; i<=n; i++) {
if(a[i]<=a[i-1]) cur += a[i-1] - a[i] + 1;
l[i] = cur;
}
cur = 0;
for(int i=n-1; i>=1; i--){
if(a[i]<=a[i+1]) cur += a[i+1] - a[i] + 1;
r[i] = cur;
}
for(int i=1; i<=n; i++) ans = min(ans,max(l[i],r[i]));
cout << ans;
cerr << "\nTIME: " << clock() << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |