| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1282175 | swishy123 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 17 ms | 5124 KiB |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int def = 1e6+1;
const int maxk = 18;
const ll inf = 1e18;
void solve(){
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
a.push_back(0);
n++;
vector<int> b(n, 0);
for (int i = 1; i < n; i++)
b[i] = a[i] - a[i - 1];
b[0] = a[0];
vector<ll> pref(n, 0ll);
vector<ll> suff(n, 0ll);
ll crr = 0;
for (int i = 0; i < n; i++){
crr += max(-b[i] + 1, 0);
pref[i] = crr;
}
crr = 0;
for (int i = n - 1; i >= 0; i--){
crr += max(b[i] + 1, 0);
suff[i] = crr;
}
ll res = inf;
for (int i = 0; i < n - 1; i++)
res = min(res, max(pref[i], suff[i + 1]));
cout << res;
}
/*
0 0 0 0 0
*/
main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (ifstream("input.txt").good()){
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int t = 1;
while (t--){
solve();
cout << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
