#include "bits/stdc++.h"
#define puba push_back
#define mapa make_pair
#define ff first
#define ss second
#define bend(_x) (_x).begin(), (_x).end()
#define szof(_x) ((int) (_x).size())

using namespace std;
typedef long long ll;
typedef double dbl;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
const int MAXN = 505, MAXC = 1e5 + 5;
const ll INF = 1e18;

int n, mk;
vector <int> v;
ll d[MAXN][MAXN];
int from[MAXN][MAXN];
map <int, vector <ll>> d0;

int main() {    
    freopen("traffic.in", "r", stdin);
    freopen("traffic.out", "w", stdout);    

    /*
    for (int i = 0; i <= 4; ++i) {
        cerr << d0[2][i] << endl;
    }*/

    //cin >> n >> mk;
    scanf("%d%d", &n, &mk);

    for (int i = 0; i < n; ++i) {
        int num;
        //cin >> num;
        scanf("%d", &num);
        d0[num] = vector <ll> (MAXN);
        //cerr << szof(d0[num]) << endl;
        v.puba(num);
    }

    for (int i = 1; i < MAXN; ++i) {
        ll prev = 0;
        for (int j = 1; j < MAXC; ++j) {
            ll tmp = (ll) (j - 1 + j % i - 1) * (j / i + 1) / 2;
            tmp -= j - 1;
            if (j % i == 0) {
                tmp += 1;
            }
            prev += tmp; 
            if (d0.count(j)) {
                d0[j][i] = prev;
            }
        }
    }

    //cerr << d0[100000][1] << endl;

    for (int i = 0; i < MAXN; ++i) {
        for (int j = 0; j < MAXN; ++j) {            
            d[i][j] = INF;
        }
    }

    d[0][0] = 0;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= mk; ++j) {
            for (int k = 0; k + j <= mk; ++k) {
                //d[i][k + j] = min(d[i][k + j], d[i - 1][k] + d0[j][v[i - 1]]);
                if (d[i][k + j] > d[i - 1][k] + d0[v[i - 1]][j]) {
                    d[i][k + j] = d[i - 1][k] + d0[v[i - 1]][j];
                    from[i][k + j] = k;
                }
            }
        }
    }

    int pos = mk;

    printf("%I64d\n", d[n][pos]);

    vector <int> ans;

    for (int i = n; i > 0; --i) {
        ans.puba(pos - from[i][pos]);
        pos = from[i][pos];
    }

    reverse(bend(ans));

    for (int num: ans) {
        printf("%d ", num);
    }
    printf("\n");

    return 0;
}
