Submission #756749

#TimeUsernameProblemLanguageResultExecution timeMemory
756749peraGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 ms212 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N = 30000 + 1;

main(){
    int n;cin >> n;
    vector<int> a(n + 1) , p(n + 1) , s(n + 1);
    for(int i = 1;i <= n;i ++){
        cin >> a[i];
    }
    for(int i = 2;i <= n;i ++){
        p[i] = p[i - 1];
        if(a[i] <= a[i - 1]) p[i] += a[i - 1] - a[i] + 1;
    }
    for(int i = n - 1;i >= 1;i --){
        s[i] = s[i + 1];
        if(a[i] >= a[i + 1]) s[i] += a[i] - a[i + 1] + 1;
    }
    int ans = LLONG_MAX;
    for(int i = 1;i <= n;i ++){
        ans = min(ans , p[i] + s[i + 1]);
    }
    cout << ans << endl;
}

Compilation message (stderr)

Main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...