#include <bitset>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <system_error>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#define pb push_back
#define MOD 1000000007
#define NMAX 200001
#define nl '\n'
#define pii1 pair<int, pair<int,int>> (1,(1,2));
#define pii pair<int,int>
#define tpl tuple<int,int,int>
#define int long long
using namespace std;
ifstream fin("data.in");
ofstream fout("data.out");
const int INF=1e12;
/*
====================DEMONSTRATION======================
5
3 2 2 3 1
pref: 0 2 3 3 6
suf: 3 3 2 0 0
=========================END===========================
*/
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<int>v(n+1);
for(int i=1;i<=n;++i)
cin>>v[i];
vector<int>pref(n+1),suf(n+1);
pref[1]=0;
suf[n]=0;
for(int i=2;i<=n;++i)
{
pref[i]=pref[i-1];
if(v[i]<=v[i-1])
pref[i]+=(v[i-1]-v[i]+1);
}
for(int i=n-1;i>=1;--i)
{
suf[i]=suf[i+1];
if(v[i]<=v[i+1])
suf[i]+=(v[i+1]-v[i]+1);
}
int ans=1e18;
for(int i=1;i<=n;++i)
{
cout<<pref[i]<<" "<<suf[i]<<nl;
ans=min(ans,max(pref[i],suf[i]));
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |