Submission #942159

#TimeUsernameProblemLanguageResultExecution timeMemory
942159dsyzGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
40 / 100
1006 ms5464 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]); } 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]); } total -= min(Ldiff,Rdiff); ans = min(ans,total); } cout<<ans<<'\n'; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:9:13: warning: variable 'A' set but not used [-Wunused-but-set-variable]
    9 |  ll arr[N], A[N];
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...