Submission #534155

#TimeUsernameProblemLanguageResultExecution timeMemory
534155BiazGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
111 ms8516 KiB
#include <bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define X first #define Y second #define ist insert typedef long long ll; //typedef pair<int,int> pii; using namespace std; int max(int a,int b){return a>b?a:b;} int min(int a,int b){return a<b?a:b;} const int INF=17000000000000000;//2147483647; const int MOD=998244353;//1000000007; const int N=200005; int n; int a[N],b[N]; int L[N],R[N]; void calc(){ int s1=0,s2=0; for (int i=1;i<=n;i++){ if (b[i]<=0) s1+=-b[i]+1; L[i]=s1; } for (int i=n;i>=1;i--){ if (b[i]>=0) s2+=b[i]+1; R[i]=s2; } } void sol(){ cin >>n; for (int i=1;i<=n;i++) cin >>a[i]; for (int i=1;i<=n;i++) b[i]=a[i]-a[i-1]; calc(); int ans=INF; for (int i=1;i<=n;i++) ans=min(ans,max(L[i],R[i+1])); cout <<ans<<'\n'; } signed main() { int _=1; //cin >>_; while (_--) sol(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...