Submission #535356

#TimeUsernameProblemLanguageResultExecution timeMemory
535356PikaQGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
25 ms7076 KiB
#include<bits/stdc++.h> #define forn(i,n) for(int i = 0;i < (n);i++) #define Forn(i,n) for(int i = 1;i <= (n);i++) #define all(p) p.begin(),p.end() #define pb push_back #define int long long #define vi vector<int> #define pii pair<int,int> #define debug(x) cout << #x << ' ' << x << '\n'; using namespace std; int n; void solve(){ cin >> n; vi a(n),l(n),r(n); forn(i,n) cin >> a[i]; int hei = 0; forn(i,n){ if(i && a[i] <= a[i-1]){ l[i] = a[i-1] - a[i] + 1; } if(i != n-1 && a[i] <= a[i+1]){ r[i] = a[i+1] - a[i] + 1; } } forn(i,n) if(i) l[i] += l[i-1]; for(int i = n-1;i >= 0;i--) if(i != n-1) r[i] += r[i+1]; int ans = (int)1e18 + 9; forn(i,n){ ans = min(ans,max(l[i],r[i])); } cout << ans << '\n'; } signed main(){ cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0); solve(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:18:6: warning: unused variable 'hei' [-Wunused-variable]
   18 |  int hei = 0;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...