Submission #1000253

#TimeUsernameProblemLanguageResultExecution timeMemory
1000253vicvicGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++11
0 / 100
1 ms2392 KiB
#include <iostream> #include <fstream> using namespace std; const int nmax=2e5+5; 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=1;i<=n;i++) { pre[i]=pre[i-1]; if (dist[i]<=0) { pre[i]+=(-dist[i])+1; } } for (int i=n;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...