#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[2020];
int b[2020];
int main(void) {
  int n, k;
  int i;
  int o;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  sort(a + 1, a + n + 1, greater<pair<int, int> >());
  for (i = 1, o = 0; i <= k; i++) {
    o += a[i].first;
    b[i] = a[i].second;
  }
  sort(b + 1, b + k + 1);
  printf("%d\n", o);
  for (i = 1, b[k] = n; i <= k; i++) printf("%d ", b[i] - b[i - 1]);
  putchar('\n');
  return 0;
}
