题目链接:Problem - 1139B - Codeforces
又双叒叕一次没看数据范围, 少填了一个2, 但是为何是t不是re?
这题观察题目看不懂(机翻看不懂)就直接看题目下面给的提示, 题意差不多是从后到前加, 只能加比上一个数字更小的数字
ac代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, b) for (ll i = (a); i <= (b); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepr(i, a, b) for (ll i = (b); i > (a); i--)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
ll cnt,n,m,t,ans,ant;
const int N=2e5+10;
ll arr[N];
string str;
inline ll read()
{
char c = getchar();int x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}//是符号
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}//是数字
return x*s;
}
void solve()
{
n=read();
rep(i,1,n) arr[i]=read();
ll mmax=arr[n];
ans=arr[n];
rrep(i,1,n-1)
{
mmax--;
if(arr[i]>=mmax)
ans+=mmax;
else
{
mmax=arr[i];
ans+=arr[i];
}
if(mmax==0) break;//防止负数加入ans
}
cout<<ans;
return;
}
int main()
{
solve();
return 0;
}