제출 #650003

#제출 시각아이디문제언어결과실행 시간메모리
650003tigarGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } ll a[200020]; ll preff[200020], suff[200020]; ll razlike[200020]; int main() { speed(); int n; cin>>n; for(int i=1; i<=n; i++)cin>>a[i]; for(int i=2; i<=n; i++)razlike[i]=a[i]-a[i-1]; for(int i=2; i<=n; i++) { preff[i]=preff[i-1]; if(razlike[i]<=0)preff[i]+=(-razlike[i]+1); } for(int i=n-1; i>=1; i--) { suff[i]=suff[i+1]; if(razlike[i+1]>=0)suff[i]+=(razlike[i+1]+1); } //for(int i=0; i<n; i++)cout<<suff[i]<<" "<<preff[i]<<" "<<razlike[i]<<endl; ll rezz=INT_MAX; for(int i=1; i<=n; i++) { rezz=min(rezz, max(suff[i], preff[i])); } cout<<rezz; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...