Submission #942054

#TimeUsernameProblemLanguageResultExecution timeMemory
942054dsyzGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
155 ms492 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; vector<ll> diff; for(ll i = 1;i <= split;i++){ total += max(0ll,(arr[i - 1] + 1) - arr[i]); diff.push_back(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]); diff.push_back(max(0ll,(arr[i - 1] + 1) - arr[i])); arr[i] = max(arr[i],arr[i + 1] + 1); } sort(diff.begin(),diff.end(),greater<ll>()); for(ll i = 1;i < diff.size();i += 2){ total -= diff[i]; } ans = min(ans,total); for(ll i = 0;i < N;i++){ arr[i] = A[i]; //reset } } cout<<ans<<'\n'; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:29:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(ll i = 1;i < diff.size();i += 2){
      |                ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...