#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v[i] = make_pair(x, i);
  }
  sort(v.begin(), v.end());
  int sum = 0;
  vector<int> indexes(k);
  for (int i = 0; i < k; i++) {
    sum += v[n - i - 1].first;
    indexes[i] = v[n - i - 1].second + 1;
  }
  cout << sum << endl;
  sort(indexes.begin(), indexes.end());
  int prev = 0;
  vector<int> res(k);
  for (int i = 0; i < k; i++) {
    if (i != k - 1) {
      res[i] = indexes[i] - prev;
      prev = indexes[i];
    } else {
      res[i] = n - prev;
    }
  }
  for (int i = 0; i < k; i++) cout << res[i] << " ";
  return 0;
}
