| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1355923 | truongthaiduonglaptrinh | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 0 ms | 344 KiB |
// duonglaptrinh
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int n;
long long a[N], l[N], r[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen("nhap.inp", "r")) {
freopen("nhap.inp", "r", stdin);
freopen("nhap.out", "w", stdout);
}
cin>>n;
for(int i = 1; i <= n; i++) {
cin>>a[i];
}
for(int i = 1; i <= n; i++) {
l[i] = l[i - 1] + max(0LL, a[i - 1] - a[i] + 1);
}
for(int i = n; i >= 1; i--) {
r[i] = r[i + 1] + max(0LL, a[i + 1] - a[i] + 1);
}
long long ans = l[n];
for(int i = 1; i <= n; i++) {
long long s = max(l[i - 1], r[i]);
ans = min(ans, s);
}
cout<<ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
