Submission #393407

#TimeUsernameProblemLanguageResultExecution timeMemory
393407ahmetGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
33 ms6892 KiB
#include <bits/stdc++.h>
using namespace std;
#define zaman cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "
#define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long (i)=(a); (i)<=(b); ++(i))	
#define endl '\n'
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define mp make_pair
const int mx=2e5+6;
ll l[mx],r[mx];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll n;cin >> n;
	ll ans=1e18+2;
	vector <ll> a(n+1);
	ref(i,1,n)cin >> a[i];
	ref(i,2,n){
		l[i]=l[i-1]+max(0LL,a[i-1]-a[i]+1);
	}
	for(int i=n-1;i>=1;--i){
		r[i]=r[i+1]+max(0LL,a[i+1]-a[i]+1);	
	}
	for(int i=1;i<=n;++i){
		ans=min(ans,max(l[i],r[i]));
	}
	cout << ans << endl;
}	

	

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:5:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define ref(i,a,b) for (long long (i)=(a); (i)<=(b); ++(i))
      |                                   ^
Main.cpp:18:2: note: in expansion of macro 'ref'
   18 |  ref(i,1,n)cin >> a[i];
      |  ^~~
Main.cpp:5:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define ref(i,a,b) for (long long (i)=(a); (i)<=(b); ++(i))
      |                                   ^
Main.cpp:19:2: note: in expansion of macro 'ref'
   19 |  ref(i,2,n){
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...