#include <bits/stdc++.h>
using namespace std;
vector<int> aux;
map<int, int> m;
int arr[2003];
int main() {
  ios_base::sync_with_stdio(false);
  ;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    aux.push_back(arr[i]);
  }
  sort(aux.rbegin(), aux.rend());
  int resp = 0;
  for (int i = 0; i < k; i++) {
    resp += aux[i];
    m[aux[i]]++;
  }
  cout << resp << endl;
  vector<int> dias;
  int last = -1;
  for (int i = 0; i < n; i++) {
    int at = arr[i];
    for (int j = 0; j < k; j++) {
      if (at == aux[j]) {
        if (k != 1)
          dias.push_back(i - last);
        else
          dias.push_back((n - 1) - last);
        last = i;
        aux[j] = -0x3f3f3f3f;
        k--;
        sort(aux.rbegin(), aux.rend());
        break;
      }
    }
  }
  for (int i = 0; i < dias.size(); i++) {
    cout << dias[i] << " ";
  }
  return 0;
}
