#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  scanf("%lld", &n);
  scanf("%lld", &k);
  long long i, a[n];
  vector<pair<long long, long long> > v;
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    v.push_back(make_pair(a[i], i));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long ans = 0;
  map<long long, long long> m;
  vector<long long> kk;
  for (i = 0; i < k; i++) {
    ans += v[i].first;
    kk.push_back(v[i].second);
  }
  cout << ans << endl;
  sort(kk.begin(), kk.end());
  if (k == 1) {
    cout << n << endl;
    return 0;
  }
  cout << kk[0] + 1 << " ";
  for (i = 1; i < kk.size() - 1; i++) {
    cout << kk[i] - kk[i - 1] << " ";
  }
  if (k > 1)
    cout << n - 1 - kk[i - 1] << endl;
  else
    cout << endl;
}
