You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
435 B
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long a[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lld", a + i);
long long ans = 0, cut = numeric_limits<long long>::max();
for (int i = n - 1; i >= 0; i--) {
cut = min(cut - 1, a[i]);
if (cut <= 0) break;
ans += cut;
}
printf("%lld", ans);
return 0;
}