Submission #371264

#TimeUsernameProblemLanguageResultExecution timeMemory
371264arnold518Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
38 ms5100 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5; const ll INF = 1e18; int N; ll A[MAXN+10]; ll ans=INF; ll B[MAXN+10], C[MAXN+10]; int main() { scanf("%d", &N); for(int i=1; i<=N; i++) scanf("%lld", &A[i]); for(int i=2; i<=N; i++) { B[i]=B[i-1]+max(0ll, A[i-1]+1-A[i]); } for(int i=N-1; i>=1; i--) { C[i]=C[i+1]+max(0ll, A[i+1]+1-A[i]); } ll ans=INF; for(int i=1; i<N; i++) { ll t=max(B[i], C[i+1]); if(A[i]+B[i]==A[i+1]+C[i+1]) t++; ans=min(ans, t); } ans=min(ans, B[N]); ans=min(ans, C[1]); printf("%lld\n", ans); }

Compilation message (stderr)

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