#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e6;
const int Inf = 1e9 + 7;
int N, M;
struct none {
  int x, y;
  int fg;
} A[Maxn];
bool cmp(none a, none b) { return a.x > b.x; }
bool cmpp(none a, none b) { return a.y < b.y; }
int main() {
  while (cin >> N >> M) {
    for (int i = 1; i <= N; i++) {
      scanf(" %d", &A[i].x);
      A[i].y = i, A[i].fg = 0;
    }
    sort(A + 1, A + N + 1, cmp);
    int sum = 0;
    for (int i = 1; i <= M; i++) A[i].fg = 1, sum += A[i].x;
    sort(A + 1, A + N + 1, cmpp);
    int d = 0;
    printf("%d\n", sum);
    int re = 0;
    for (int i = 1; i <= N; i++) {
      if (A[i].fg == 1) {
        d++;
        if (d != M)
          printf("%d", i - re);
        else
          printf("%d", N - re);
        re = i;
        if (d != M) printf(" ");
      }
    }
    printf("\n");
  }
}
