# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1158086 | nguyn | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 16 ms | 4952 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 2e5 + 5;
int n, a[N];
int pre[N], suf[N];
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 2; i <= n; i++) {
pre[i] = pre[i - 1] + max(0ll, a[i - 1] - a[i] + 1);
}
for (int i = n - 1; i >= 1; i--) {
suf[i] = suf[i + 1] + max(0ll, a[i + 1] - a[i] + 1);
}
int res = 1e18;
for (int i = 1; i <= n; i++) {
res = min(res, max(pre[i], suf[i]));
}
cout << res;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |