#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long cnt = 0, sum = 0, i, j, k;
  long long n;
  cin >> n >> k;
  pair<long long, long long> v[n];
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    v[i] = {k, i};
  }
  sort(v, v + n,
       [&](pair<long long, long long> a, pair<long long, long long> b) {
         return a.first > b.first;
       });
  vector<long long> a;
  for (long long i = 0; i < k; i++) {
    sum += v[i].first;
    a.push_back(v[i].second + 1);
  }
  sort(a.begin(), a.end());
  a.pop_back();
  a.push_back(n);
  vector<long long> ans;
  long long l = 0;
  for (long long i = 0; i < a.size(); i++) {
    ans.push_back(a[i] - l);
    l = a[i];
  }
  cout << sum << endl;
  for (auto x : ans) cout << x << " ";
}
void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  init();
  { solve(); }
  return 0;
}
