#include <bits/stdc++.h>
using namespace std;
signed main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int> > v(N);
  vector<int> idx(K);
  for (int i = 0; i < N; ++i) {
    int X;
    cin >> X;
    v[i] = make_pair(X, i);
  }
  sort(v.rbegin(), v.rend());
  int sum = 0;
  for (int i = 0; i < K; ++i) {
    sum += v[i].first;
    idx[i] = v[i].second;
  }
  cout << sum << endl;
  sort(idx.begin(), idx.end());
  if (K == 1)
    cout << N << endl;
  else {
    for (int i = 0; i < K; ++i) {
      if (i == 0)
        cout << idx[0] + 1;
      else if (i == K - 1)
        cout << " " << N - idx[i - 1] - 1;
      else
        cout << " " << idx[i] - idx[i - 1];
    }
    cout << endl;
  }
}
