Submission #386074

#TimeUsernameProblemLanguageResultExecution timeMemory
386074CaroLindaGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
46 ms10220 KiB
#include <bits/stdc++.h> #define lp(i,a,b) for(int i = a ; i < b; i++) #define ll long long #define all(x) x.begin(),x.end() #define pb push_back #define mk make_pair #define pii pair<int,int> #define sz(x) (int)(x.size()) #define ff first #define ss second const int MAXN = 2e5+10 ; using namespace std ; int N ; ll A[MAXN] , suf[MAXN] , pref[MAXN] ; ll valSuf[MAXN] , valPref[MAXN] ; int main() { scanf("%d", &N ) ; for(int i = 1 ; i <= N ; i++ ) scanf("%lld", &A[i]) ; lp(i,1,N+1) { valPref[i] = valPref[i-1]+(A[i]-A[i-1]) ; pref[i] = pref[i-1] ; if( A[i] <= A[i-1] ) { pref[i] += A[i-1]-A[i]+1 ; valPref[i] = valPref[i-1]+(A[i-1]-A[i]+1) ; } } for(int i = N ; i > 0 ; i-- ) { valSuf[i] = valSuf[i+1]+(A[i]-A[i+1]) ; suf[i] = suf[i+1] ; if( A[i] <= A[i+1] ) { suf[i] += A[i+1]-A[i]+1 ; valSuf[i] = valSuf[i+1]+(A[i+1]-A[i]+1) ; } } ll ans = pref[N] ; lp(i,1,N+1) ans = min(ans, max(pref[i],suf[i]) ) ; printf("%lld\n" , ans ) ; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  scanf("%d", &N ) ;
      |  ~~~~~^~~~~~~~~~~
Main.cpp:24:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |  for(int i = 1 ; i <= N ; i++ ) scanf("%lld", &A[i]) ;
      |                                 ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...