Submission #935824

#TimeUsernameProblemLanguageResultExecution timeMemory
935824koukirocksGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
21 ms5480 KiB
#include <bits/stdc++.h> #define speed ios_base::sync_with_stdio(0); cin.tie(0) #define all(x) (x).begin(),(x).end() using namespace std; typedef long long ll; typedef double db; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll MAX=2e5+10,P=998244353; const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f; int n; ll a[MAX]; ll rt[MAX]; int main() { speed; cin>>n; ll last=0; for (int i=1;i<=n;i++) { cin>>a[i]; a[i]=a[i]-last; last+=a[i]; // cout<<a[i]<<" "; } // cout<<"\n"; ll ans=oo; rt[n+1]=0; for (int i=n;i>=1;i--) { rt[i]=rt[i+1]+max(0ll,a[i]+1); } ll lft=0; for (int i=1;i<=n+1;i++) { ans=min(ans,max(lft,rt[i])); lft+=max(0ll,1-a[i]); } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...