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
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
 
    vector<int> dp(n);
    for (int i = 0; i < n; i++)
    {
        dp[i] = 0;
        for (int j = 0; j < n; j++)
        {
            if (i == j) continue;
            int dy = abs(i - j);
            int dx = abs(p[i] - p[j]);
            dp[i] = max(dp[i], dy + dx);
        }
    }
 
    for (int i = 0; i < n; i++)
        cout << dp[i] << " ";
 
    cout << endl;
    return 0;
}