import java.util.*;
import java.io.*;

public class traffic_dp {
    FastScanner in;
    PrintWriter out;

    public long calcAnger(int cars, int carsPerTraffic) {
        long anger = 0;
        int cnt = cars / carsPerTraffic;
        anger -= cnt * 1L * cars - carsPerTraffic * 1L * cnt * (cnt + 1) / 2;
        anger -= cars * 1L * carsPerTraffic * cnt * (cnt + 1);
        anger += cnt * 1L * cars * cars;
        anger += cnt * 1L * (cnt + 1) * (2 * cnt + 1) / 6 * carsPerTraffic * carsPerTraffic;
        return anger;
    }

    public void solve() throws IOException {
        int n = in.nextInt(), k = in.nextInt();
        int[] cars = new int[n];
        for (int i = 0; i < n; i++) {
            cars[i] = in.nextInt();
        }
        long[][] dp = new long[n + 1][k + 1];
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= k; j++) {
                dp[i][j] = Long.MAX_VALUE / 2;
            }
        }
        int[][] previous = new int[n + 1][k + 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 w = calcAnger(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 leftK = k;
        int[] answer = new int[n];
        int index = 0;
        while (road > 0) {
            int p = previous[road][leftK];
            answer[index++] = leftK - p;
            leftK = p;
            road--;
        }
        for (int i = 0; i < n / 2; i++) {
            int tmp = answer[i];
            answer[i] = answer[n - i - 1];
            answer[n - i - 1] = tmp;
        }
        out.println(dp[n][k] / 2);
        for (int i = 0; i < n; i++) {
            out.print(answer[i]);
            if (i < n - 1) {
                out.print(" ");
            } else {
                out.println("\n");
            }
        }        
    }

    public void run() {
        try {
            in = new FastScanner(new File("traffic.in"));
            out = new PrintWriter(new File("traffic.out"));

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }

    public static void main(String[] arg) {
        new traffic_dp().run();
    }
}
