#include <bits/stdc++.h>
using namespace std;
struct node {
  int num;
  int x;
} sum[2020];
int cmp(node a, node b) {
  if (a.num == b.num)
    return a.x > b.x;
  else
    return a.num < b.num;
}
int main() {
  int n, m;
  int alp[2020];
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &sum[i].num);
    sum[i].x = i;
  }
  sort(sum, sum + n, cmp);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    ans += sum[n - 1 - i].num;
  }
  printf("%d\n", ans);
  for (int i = 0; i < m; i++) {
    alp[i] = sum[n - 1 - i].x;
  }
  sort(alp, alp + m);
  if (m == 1) {
    printf("%d\n", n);
  } else {
    int cnt = alp[0] + 1;
    printf("%d ", alp[0] + 1);
    for (int i = 1; i < m - 1; i++) {
      printf("%d ", alp[i] - alp[i - 1]);
      cnt += (alp[i] - alp[i - 1]);
    }
    printf("%d\n", n - cnt);
  }
  return 0;
}
