#include <bits/stdc++.h>
using namespace std;
struct node {
  int pos, num;
} p[2005];
bool cmp1(node q, node e) { return q.pos < e.pos; }
bool cmp(node a, node b) {
  if (a.num != b.num) return a.num > b.num;
  return a.pos < b.pos;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i].num);
    p[i].pos = i;
  }
  sort(p + 1, p + n + 1, cmp);
  int sum = 0;
  for (int i = 1; i <= m; i++) sum += p[i].num;
  printf("%d\n", sum);
  sort(p + 1, p + m + 1, cmp1);
  p[0].pos = 0;
  for (int i = 1; i < m; i++) printf("%d ", p[i].pos - p[i - 1].pos);
  printf("%d\n", n - p[m].pos + p[m].pos - p[m - 1].pos);
  return 0;
}
