#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int> > v;
  vector<long long int> vec(n, 0);
  for (long long int i = 0; i < n; i++) {
    cin >> vec[i];
    v.push_back({vec[i], i});
  }
  if (k == 1) {
    long long int maxi = 0;
    for (long long int i = 0; i < n; i++) maxi = max(vec[i], maxi);
    cout << maxi << endl;
    cout << n << endl;
    return 0;
  }
  sort(v.rbegin(), v.rend());
  vector<long long int> ans;
  for (long long int i = 0; i < k; i++) {
    ans.push_back(v[i].second);
  }
  sort(ans.begin(), ans.end());
  long long int sum = 0;
  vector<long long int> print;
  long long int maxi = 0, c = 0;
  for (long long int i = 0; i < ans.size(); i++) {
    maxi = 0, c = 0;
    if (i == 0) {
      for (long long int j = 0; j <= ans[i]; j++) {
        maxi = max(vec[j], maxi);
        c++;
      }
    } else if (i < ans.size() - 1) {
      for (long long int j = ans[i - 1] + 1; j <= ans[i]; j++) {
        maxi = max(vec[j], maxi);
        c++;
      }
    } else {
      for (long long int j = ans[i - 1] + 1; j < n; j++) {
        maxi = max(vec[j], maxi);
        c++;
      }
    }
    sum += maxi;
    print.push_back(c);
  }
  cout << sum << endl;
  for (long long int i = 0; i < print.size(); i++) {
    cout << print[i] << " ";
  }
}
