https://www.acmicpc.net/problem/2847
#include<stdio.h>
int main() {
int n;
scanf("%d",&n);
int arr[n];
int count=0;
for(int i=0;i<n;i++) scanf("%d",&arr[i]);
for(int i=n-1;i>0;i--){
if(arr[i]<=arr[i-1]){
count+=arr[i-1]-arr[i]+1;
arr[i-1]=arr[i]-1;
}
}
printf("%d",count);
}