제출 #788059

#제출 시각아이디문제언어결과실행 시간메모리
788059winter0101Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
21 ms6956 KiB
#include<bits/stdc++.h> using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) #define pil pair<int,long long> const int maxn=2e5+9; long long a[maxn],b[maxn],c[maxn]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("temp.INP","r",stdin); //freopen("temp.OUT","w",stdout); int n; cin>>n; for1(i,1,n)cin>>a[i]; for1(i,2,n){ b[i]=b[i-1]+max(0ll,a[i-1]-a[i]); if (a[i-1]>=a[i])b[i]++; } for2(i,n-1,1){ c[i]=c[i+1]+max(0ll,a[i+1]-a[i]); if (a[i+1]>=a[i])c[i]++; } long long ans=1e18; for1(i,1,n){ ans=min(ans,b[i]+c[i]-min(b[i],c[i])); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...