제출 #942158

#제출 시각아이디문제언어결과실행 시간메모리
942158dsyzGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
17 ms476 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define MAXN (1000005) int main() { ios_base::sync_with_stdio(false);cin.tie(0); ll N; cin>>N; ll arr[N], A[N]; for(ll i = 0;i < N;i++){ cin>>arr[i]; A[i] = arr[i]; } ll ans = 1e18; for(ll split = 0;split < N;split++){ ll total = 0; ll Ldiff = 0,Rdiff = 0; for(ll i = 1;i <= split;i++){ total += max(0ll,(arr[i - 1] + 1) - arr[i]); Ldiff += max(0ll,(arr[i - 1] + 1) - arr[i]); arr[i] = max(arr[i],arr[i - 1] + 1); } for(ll i = N - 2;i >= split;i--){ total += max(0ll,(arr[i + 1] + 1) - arr[i]); Rdiff += max(0ll,(arr[i + 1] + 1) - arr[i]); arr[i] = max(arr[i],arr[i + 1] + 1); } total -= min(Ldiff,Rdiff); ans = min(ans,total); for(ll i = 0;i < N;i++){ arr[i] = A[i]; //reset } } cout<<ans<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...