Submission #736397

#TimeUsernameProblemLanguageResultExecution timeMemory
736397shoryu386Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
91 ms1872 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n; int arr[200007]; pair<int, int> solve(int tp){ int linc = 0; for (int x = 1; x <= tp; x++){ if (arr[x-1] >= arr[x]){ //enforce an increase linc += arr[x-1] - arr[x] + 1; } } int rinc = 0; for (int x = n-2; x >= tp; x--){ if (arr[x+1] >= arr[x]){ //enforce an increase rinc += arr[x+1] - arr[x] + 1; } } //cout << tp << ' ' << linc << ' ' << rinc << '\n'; return make_pair(linc, rinc); } main(){ cin >> n; for (int x = 0; x < n; x++) cin >> arr[x]; pair<int, int> lr = solve(0); int ans = max(lr.first, lr.second); for (int x = 1; x < n; x++) { if (arr[x-1] >= arr[x]){ //enforce an increase lr.first += arr[x-1] - arr[x] + 1; } if (x == n-1){ lr.second = 0; } else if (arr[x] >= arr[x-1]){ //enforce an increase lr.second -= arr[x] - arr[x-1] + 1; } ans = min(ans, max(lr.first, lr.second)); } cout << ans; }

Compilation message (stderr)

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