Submission #443772

#TimeUsernameProblemLanguageResultExecution timeMemory
443772jamezzzGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
32 ms6168 KiB
#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;

typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements

#define DEBUG

#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

int n,a[200005];
ll p[200005],s[200005];

int main(){
	sf("%d",&n);
	for(int i=0;i<n;++i)sf("%d",&a[i]);
	for(int i=1;i<n;++i)p[i]=p[i-1]+max(0,a[i-1]-a[i]+1);
	for(int i=n-2;i>=0;--i)s[i]=s[i+1]+max(0,a[i+1]-a[i]+1);
	ll ans=LINF;
	for(int i=0;i<n;++i)ans=min(ans,max(p[i],s[i]));
	pf("%lld\n",ans);
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:45:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  sf("%d",&n);
      |    ^
Main.cpp:46:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  for(int i=0;i<n;++i)sf("%d",&a[i]);
      |                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...