Submission #568681

#TimeUsernameProblemLanguageResultExecution timeMemory
568681dantoh000Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
41 ms11656 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int n; int a[200005]; int diff[200005]; int c[200005]; int d[200005]; int pc[200005]; int pd[200005]; main(){ scanf("%lld",&n); for (int i = 0; i < n; i++){ scanf("%lld",&a[i]); if (i) diff[i] = a[i]-a[i-1]; } for (int i = 1; i < n; i++){ c[i] = max(0ll,1-diff[i]); d[i] = max(0ll,diff[i]+1); ///printf("%d: to 1 = %d, to -1 = %d\n",diff[i],c[i],d[i]); pc[i] = pc[i-1] + c[i]; } for (int i = n-1; i >= 1; i--){ pd[i] = pd[i+1] + d[i]; } int ans = -1; for (int i = 1; i <= n; i++){ int NC = max(pc[i-1],pd[i]); if (ans == -1 || ans > NC) ans = NC; } printf("%lld\n",ans); }

Compilation message (stderr)

Main.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
Main.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...