Submission #862078

#TimeUsernameProblemLanguageResultExecution timeMemory
862078vjudge1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
24 ms8736 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define F first #define S second #define endl '\n' #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() const int mod = 1e9 + 7; const int N = 1e6 + 15; const ll inf = 1e18; int a[N], n; ll dp1[N], dp2[N]; int main(){ scanf("%d", &n); for (int i=0;i<n;i++){ scanf("%d", a+i); } for (int i=1;i<n;i++){ dp1[i] = dp1[i-1] + max(0, a[i-1]-a[i]+1); } for (int i=n-2;i>=0;i--){ dp2[i] = dp2[i+1] + max(0, a[i+1]-a[i]+1); } ll ans = inf; for (int i=0;i<n;i++){ ans = min(ans, max(dp1[i], dp2[i])); } printf("%lld", ans); }

Compilation message (stderr)

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