Submission #534150

#TimeUsernameProblemLanguageResultExecution timeMemory
534150BiazGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
40 / 100
1033 ms5316 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 calc(int k){ int s1=0,s2=0; for (int i=1;i<=k;i++) if (b[i]<=0) s1+=-b[i]+1; for (int i=n;i>k;i--) if (b[i]>=0) s2+=b[i]+1; return max(s1,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]; int ans=INF; for (int i=1;i<=n;i++) ans=min(ans,calc(i)); cout <<ans<<'\n'; } signed main() { int _=1; //cin >>_; while (_--) sol(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...