Coding Test - cpp/Greedy
[백준 2847: 게임을 만든 동준이] - C++
에드윈H
2021. 2. 2. 14:51
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* arr = new int[5];
for (int i = 0; i < n; i++)
{
int input;
cin >> input;
arr[i] = input;
}
int result = 0;
int ch = 0;
for (int i = n-1; i >0; i--)
{
if (arr[i] <= arr[i-1])
{
ch = arr[i-1] - arr[i] + 1;
arr[i-1] -= ch;
result += ch;
}
}
cout << result << endl;
delete[] arr;
return 0;
}