#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v(n);
  vector<int> v2(k);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first;
    v[i].second = i + 1;
  }
  sort(v.begin(), v.end());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += v[n - 1 - i].first;
    v2[i] = v[n - 1 - i].second;
  }
  cout << sum << endl;
  sort(v2.begin(), v2.end());
  for (int i = k - 1; i > 0; i--) {
    v2[i] = v2[i] - v2[i - 1];
  }
  int cnt = 0;
  for (int i = 0; i < k - 1; i++) {
    cout << v2[i] << ' ';
    cnt += v2[i];
  }
  cout << n - cnt;
  return 0;
}
