이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define mxn 200005
#define mxm 105
#define f first
#define s second
#define pb push_back
#define es " "
#define endl '\n'
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
typedef pair<string, string> pii;
typedef pair<int, pii> pip;
int n, v[mxn], ma, pos, pos2, pos3;
ll need[mxn], resp, atual;
int main(){
fastio;
cin >> n;
for(int i=1; i<=n; i++){
cin >> v[i];
if(v[i]>=ma){
ma=v[i];
pos=i;
}
}
for(int i=n; i>=pos; i--){
if(v[i]<=v[i+1]+need[i+1]){
need[i]=(v[i+1]+need[i+1])-v[i]+1;
}
}
for(int i=1; i<=pos; i++){
if(v[i]<=v[i-1]+need[i-1]){
need[i]=(v[i-1]+need[i-1])-v[i]+1;
}
}
pos2=1, pos3=n;
for(int i=pos-1; i>=1; i--){
if(need[i]){
pos2=i;
break;
}
}
for(int i=pos+1; i<=n; i++){
if(need[i]){
pos3=i;
break;
}
}
for(int i=1; i<pos2; i++){
if(!need[i]){
resp+=atual;
atual=0;
}
atual=max(atual, need[i]);
}
resp+=atual;
atual=0;
for(int i=pos2; i<=pos3; i++){
if(!need[i]){
resp+=atual;
atual=0;
}
atual=max(atual, need[i]);
}
resp+=atual;
atual=0;
for(int i=pos3+1; i<=n; i++){
if(!need[i]){
resp+=atual;
atual=0;
}
atual=max(atual, need[i]);
}
resp+=atual;
cout << resp;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |