0% found this document useful (0 votes)
6 views

Competitive Programming

Uploaded by

lks992004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Competitive Programming

Uploaded by

lks992004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

OR Range:-

#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
int n;
cin>>n;
vector<int>v(n);
for(int i=0; i<n; i++){
cin>>v[i];
}
for(int i=n-2; i>=0; i--){
v[i]=max(0LL,min(v[i],v[i+1]-1));
}
int ans=0;
for(int i=0; i<n; i++){
ans+=v[i];
}
cout<<ans<<"\n";
return 0;
}

Concepts Page 1

You might also like