#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
  int s, v;
} a[20001];
int w[20001];
bool cmp(node x, node y) { return x.s > y.s; }
int main() {
  int k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].s);
    a[i].v = i;
  }
  sort(a + 1, a + 1 + n, cmp);
  int maxn = 0;
  for (int i = 1; i <= k; i++) maxn += a[i].s;
  printf("%d\n", maxn);
  for (int i = 1; i <= k; i++) w[i] = a[i].v;
  sort(w + 1, w + 1 + k);
  for (int i = 1; i < k; i++) printf("%d ", w[i] - w[i - 1]);
  printf("%d", n - w[k - 1]);
  return 0;
}
