#include <bits/stdc++.h>
using namespace std;
struct q {
  int a, index;
};
void merge(struct q *a, int l, int m, int r) {
  int i, j, k, x = m - l + 1, y = r - m;
  struct q L[x], R[y];
  for (i = 0; i < x; i++) L[i] = a[l + i];
  for (i = 0; i < y; i++) R[i] = a[m + 1 + i];
  i = 0, j = 0, k = l;
  while (i < x && j < y) {
    if (L[i].a < R[j].a)
      a[k++] = L[i++];
    else
      a[k++] = R[j++];
  }
  while (i < x) a[k++] = L[i++];
  while (j < y) a[k++] = R[j++];
}
void mergesort(struct q x[], int l, int r) {
  int m = (l + r) / 2;
  if (l < r) {
    mergesort(x, l, m);
    mergesort(x, m + 1, r);
    merge(x, l, m, r);
  }
}
void merge1(struct q *a, int l, int m, int r) {
  int i, j, k, x = m - l + 1, y = r - m;
  struct q L[x], R[y];
  for (i = 0; i < x; i++) L[i] = a[l + i];
  for (i = 0; i < y; i++) R[i] = a[m + 1 + i];
  i = 0, j = 0, k = l;
  while (i < x && j < y) {
    if (L[i].index < R[j].index)
      a[k++] = L[i++];
    else
      a[k++] = R[j++];
  }
  while (i < x) a[k++] = L[i++];
  while (j < y) a[k++] = R[j++];
}
void mergesort1(struct q x[], int l, int r) {
  int m = (l + r) / 2;
  if (l < r) {
    mergesort1(x, l, m);
    mergesort1(x, m + 1, r);
    merge1(x, l, m, r);
  }
}
int main() {
  int n, k, sum = 0, min = 0, i;
  cin >> n >> k;
  struct q x[n];
  for (i = 0; i < n; i++) {
    cin >> x[i].a;
    x[i].index = i + 1;
  }
  mergesort(x, 0, n - 1);
  for (i = 0; i < k; i++) sum = sum + x[n - 1 - i].a;
  cout << sum << endl;
  mergesort1(x, n - k, n - 1);
  for (i = 0; i < k; i++) {
    sum = x[n - k + i].index - min;
    if (i == k - 1) {
      cout << sum + n - x[n - 1].index;
      break;
    }
    cout << sum << " ";
    min = x[n - k + i].index;
  }
  return 0;
}
