#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  vector<int> s(n);
  for (int(i) = (0); i < (n); ++(i)) cin >> s[i];
  vector<int> q(n);
  for (int(i) = (0); i < (n); ++(i)) q[i] = s[i];
  sort(q.begin(), q.end());
  int maxval = q[(n - 1) - (k - 1)];
  int count = 0;
  long long sum = 0;
  for (int i = (n - 1) - (k - 1); i < q.size(); i++) {
    if (maxval == q[i]) count++;
    sum += q[i];
  }
  vector<int> ans(n);
  for (int i = 0; i < q.size(); i++) {
    if (s[i] > maxval) {
      ans[i] = 1;
    } else {
      if (s[i] == maxval) {
        if (count) {
          count--;
          ans[i] = 1;
        }
      }
    }
  }
  int val = 0;
  int ones = 0;
  cout << sum << '\n';
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i] == 1) {
      ones++;
    }
    if (ones == 2) {
      cout << val << " ";
      ones--;
      val = 0;
    }
    val++;
  }
  cout << val << endl;
  ;
  return 0;
}
