1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
std::vector<int> dane;
int main()
{
    int n,k;
    std::cin >> n >> k;
    for (int i = 0;i < n;i++){
        int x;
        std::cin >> x;
        dane.push_back(x);
    }
    long long wynik= 0LL;
    for (int i = 0;i<n;i++){
        int maks = 0;
        for (int y = 0;y<n;y++){
            maks = max(dane[y] - k * abs((y-i)),maks);
        }
        wynik += maks - dane[i];

    }
    std::cout << wynik << std::endl;
    return 0;
}