#include <bits/stdc++.h>
using namespace std;
struct type {
  int index;
  int value;
};
vector<type> vec;
vector<int> indice;
bool sortByValue(type& a, type& b) { return a.value > b.value; }
int main() {
  int n, a, k, max = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a;
    type temp;
    temp.index = i + 1;
    temp.value = a;
    vec.push_back(temp);
  }
  sort(vec.begin(), vec.end(), sortByValue);
  for (int i = 0; i < k; i++) {
    max = max + vec[i].value;
    indice.push_back(vec[i].index);
  }
  cout << max << endl;
  sort(indice.begin(), indice.end());
  int ct = 0;
  if (k > 1) {
    cout << indice[1] - 1 << " ";
    for (int i = 2; i < k; i++) {
      cout << indice[i] - indice[i - 1] << " ";
    }
    cout << n - indice[k - 1] + 1 << endl;
  } else
    cout << n << endl;
}
