#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, k, x, ans = 0;
  vector<long long> vec, sorted_vec;
  multiset<long long> mst;
  cin >> n >> k;
  vec.push_back(0);
  for (long long i = 0; i < n; i++) {
    cin >> x;
    vec.push_back(x);
  }
  sorted_vec = vec;
  sort(sorted_vec.rbegin(), sorted_vec.rend());
  long long j = 0, prev = 0;
  for (long long i = 0; i < k; i++) {
    ans += sorted_vec[i];
    mst.insert(sorted_vec[i]);
  }
  cout << ans << "\n";
  for (long long i = 1; i <= n; i++) {
    auto it = mst.find(vec[i]);
    if (it != mst.end()) {
      if (mst.size() == 1)
        cout << n - prev << "\n";
      else
        cout << i - prev << " ";
      mst.erase(it);
      prev = i;
    }
  }
  return 0;
}
