Submission #649274

#TimeUsernameProblemLanguageResultExecution timeMemory
649274milisavGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
30 ms6252 KiB
#include<bits/stdc++.h> #define maxn 300000 using namespace std; int n; int a[maxn]; long long pref[maxn]; long long suf[maxn]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } for(int i=2;i<=n;i++) { pref[i]=pref[i-1]; if(a[i]<=a[i-1]) pref[i]+=(a[i-1]-a[i]+1); } for(int i=n-1;i>=1;i--) { suf[i]=suf[i+1]; if(a[i]<=a[i+1]) suf[i]+=(a[i+1]-a[i]+1); } long long ans=1e18; for(int i=1;i<=n;i++) { ans=min(ans,max(pref[i],suf[i])); } printf("%lld\n",ans); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...