#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + n);
  reverse(a, a + n);
  long long sum = 0;
  int y = k;
  vector<pair<int, int>> r;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    r.push_back({a[i], 0});
    y--;
    if (y == 0) {
      break;
    }
  }
  cout << sum << endl;
  reverse(r.begin(), r.end());
  int space = 0;
  vector<int> e;
  for (int i = 0; i < n; i++) {
    space++;
    for (int j = 0; j < r.size(); j++) {
      if (b[i] == r[j].first) {
        if (r[j].second == 0) {
          e.push_back(space);
          space = 0;
          r[j].second = 1;
          break;
        }
      }
    }
    if (i + 1 == n) {
      e.push_back(space);
    }
  }
  if (e.size() > k) {
    for (int i = 0; i < e.size(); i++) {
      if (i + 2 == e.size()) {
        cout << e[i] + e[i + 1] << " ";
        break;
      }
      cout << e[i] << " ";
    }
    cout << endl;
  } else {
    for (int i = 0; i < e.size(); i++) {
      cout << e[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
