#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int oo = 1e9;
int n, k;
pair<int, int> a[N];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  long long anss = 0;
  vector<int> ans;
  if (n <= k) {
    for (int i = 0; i < n; i++) {
      anss += a[i].first;
      ans.push_back(1);
    }
    for (int i = n; i < k; i++) {
      ans.push_back(0);
    }
    printf("%lld\n", anss);
    for (int i = 0; i < ((int)(ans).size()); i++) {
      printf("%d ", ans[i]);
    }
    return 0;
  }
  sort(a, a + n);
  int last = -1;
  for (int i = 0; i < k; i++) {
    int MIN = 10000;
    int indx;
    for (int i = n - k; i < n; i++) {
      if (a[i].second < MIN) {
        MIN = a[i].second;
        indx = i;
      }
    }
    anss += a[indx].first;
    ans.push_back(a[indx].second - last);
    last = a[indx].second;
    a[indx].second = 1000000;
  }
  ans[((int)(ans).size()) - 1] += (n - last - 1);
  printf("%lld\n", anss);
  for (int i = 0; i < ((int)(ans).size()); i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
