Submission #620797

#TimeUsernameProblemLanguageResultExecution timeMemory
620797patrikpavic2Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
45 ms6232 KiB
#include <cstdio> #include <algorithm> using namespace std; typedef long long ll; const int N = 2e5 + 500; int n, A[N]; ll dpL[N], dpR[N]; int main(){ scanf("%d", &n); for(int i = 0;i < n;i++) scanf("%d", A + i); for(int i = 1;i < n;i++) dpL[i] = dpL[i - 1] + max(0, 1 - (A[i] - A[i - 1])); for(int i = n - 2;i >= 0;i--) dpR[i] = dpR[i + 1] + max(0, 1 - (A[i] - A[i + 1])); ll ans = (ll)1e18; for(int i = 0;i < n;i++) ans = min(ans, max(dpL[i], dpR[i])); printf("%lld\n", ans); return 0; }

Compilation message (stderr)

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