#include <bits/stdc++.h>

long long calc_anger(int cars, int cars_per_traffic) {
    long long anger = 0;
    int cnt = (cars - cars_per_traffic + 1) / cars_per_traffic;
    anger -= cnt * cars - cars_per_traffic * 1LL * cnt * (cnt + 1) / 2;
    anger += cnt * 1LL * cars * cars;
    anger += cars_per_traffic * 1LL * cars_per_traffic * cnt * (cnt + 1) * (2 * cnt + 1) / 6;
    anger -= 2LL * cars * cars_per_traffic * cnt * (cnt + 1) / 2;
    return anger;
}

int main() {
    freopen("traffic.in", "r", stdin);
    freopen("traffic.out", "w", stdout);
    int n, k;
    scanf("%d%d", &n, &k);
    std::vector<int> cars(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &cars[i]);
    }
    std::vector<std::vector<long long>> dp(n + 1, std::vector<long long>(k + 1, (long long)1e18));
    std::vector<std::vector<int>> previous(n + 1, std::vector<int>(k + 1, -1));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            for (int next = 1; next <= j; next++) {
                long long w = calc_anger(cars[i - 1], next);
                if (dp[i][j] > dp[i - 1][j - next] + w) {
                    dp[i][j] = dp[i - 1][j - next] + w;
                    previous[i][j] = j - next;
                }
            }
        }
    }
    int road = n;
    int left_k = k;
    std::vector<int> answer;
    while (road > 0) {
        int p = previous[road][left_k];
        answer.push_back(left_k - p);
        left_k = p;
        road--;
    }
    std::reverse(answer.begin(), answer.end());
    printf("%lld\n", dp[n][k] / 2);
    for (int i = 0; i < n; i++) {
        printf("%d%c", answer[i], " \n"[i == n - 1]);
    }
    return 0;
}