#include #include #include using namespace std; int main() { int N, M; cin >> N >> M; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } for (int i = 0; i < M; ++i) { A[i] -= 1; } vector> dp(M + 1, vector(N, 1e8)); for (int j = 0; j < N; ++j) { dp[M][j] = j; } for (int i = M; i > 0; --i) { for (int j = 0; j < N; ++j) { for (int k = 0; k < N; ++k) { int cost1, cost2; if (k <= j) { if (k <= A[i - 1] && A[i - 1] < j) { cost1 = j - k - 1; } else { if ((j == k) && ((j == A[i - 1]) || (j == A[i - 1] + 1))) { cost1 = 1; continue; } cost1 = j - k; } } else { cost1 = 1e8; } if (j <= k) { if (j <= A[i - 1] && A[i - 1] < k) { cost2 = k - j - 1; } else { if (((j == A[i - 1]) || (j == A[i - 1] + 1)) && (j == k)) { cost2 = 1; continue; } cost2 = k - j; } } else { cost2 = 1e8; } dp[i - 1][j] = min(dp[i - 1][j], dp[i][k] + min(cost1, cost2)); } } } vector result; for (int i = 1; i < N; ++i) { result.push_back(dp[0][i]); } for (int i = 0; i < result.size(); ++i) { cout << result[i] << " "; } cout << endl; return 0; }