제출 #1000261

#제출 시각아이디문제언어결과실행 시간메모리
1000261vicvicGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++11
100 / 100
58 ms8628 KiB
#include <iostream> #include <fstream> using namespace std; const int nmax=2e5+5; long long int n, v[nmax], dist[nmax], pre[nmax], suf[nmax]; int main() { cin >> n; for (int i=1;i<=n;i++) { cin >> v[i]; dist[i]=v[i]-v[i-1]; } long long ret=1e18; for (int i=2;i<=n;i++) { pre[i]=pre[i-1]; if (dist[i]<=0) { pre[i]+=(-dist[i])+1; } } for (int i=n-1;i>=1;i--) { suf[i]=suf[i+1]; if (dist[i+1]>=0) { suf[i]+=dist[i+1]+1; } } for (int i=1;i<=n;i++) { ret=min (ret, max (1ll*pre[i], 1ll*suf[i])); } cout << ret; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...