Submission #387150

#TimeUsernameProblemLanguageResultExecution timeMemory
387150uacoder123Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
30 ms7168 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) lli(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <ii,lli> iii;
typedef vector <lli> vi;
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli n;
  cin>>n;
  lli a[n],b[n]={},e[n]={};
  for(lli i=0;i<n;++i)
  {
    cin>>a[i];
    if(i==0)
      b[0]=0;
    else
      b[i]=max(a[i-1]+1-a[i],0*1LL)+b[i-1];
  }
  for(lli i=n-2;i>=0;--i)
    e[i]=e[i+1]+max(0*1LL,a[i+1]+1-a[i]);
  lli ans=e[0]+b[0];
  for(lli i=0;i<n;++i)
    ans=min(ans,max(b[i],e[i]));
  cout<<ans<<endl;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...