제출 #870457

#제출 시각아이디문제언어결과실행 시간메모리
870457Maite_MoraleGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
62 ms10580 KiB
#include<bits/stdc++.h> #define F first #define S second #define MAX 500005 #define oo 1e18 #define mod 1000000007 #define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0); using namespace std; typedef long long ll; #define pll pair<ll , ll> #define vll vector<ll> #define vvll vector<vll> #define vpll vector<pll> ll n,t[MAX],a[MAX],b[MAX]; int main(){ cin>>n; for(int i=0;i<n;i++)cin>>a[i]; t[n-1]=0; for(int i=n-2;i>=0;i--){ t[i]=t[i+1]+max((ll)0,(a[i+1]+1)-a[i]); }ll s=0;ll ans=oo; for(int i=0;i<n;i++){ if(i>0)s+=max((ll)0,(a[i-1]+1)-a[i]); ans=min(ans,max(s,t[i])); }cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...