#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int arr[n], brr[n];
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    brr[i] = arr[i];
  }
  sort(brr, brr + n, greater<int>());
  long long int sum = 0;
  map<long long int, long long int> m;
  for (int i = 0; i < k; i++) {
    sum += brr[i];
    m[brr[i]]++;
  }
  cout << sum << endl;
  int cnt = 0;
  vector<int> v;
  v.push_back(-1);
  for (int i = 0; i < n; i++) {
    if (m[arr[i]] > 0) {
      v.push_back(i);
      m[arr[i]]--;
    }
  }
  for (int i = 1; i < v.size() - 1; i++) {
    cout << v[i] - v[i - 1] << " ";
  }
  cout << n - v[v.size() - 2] - 1 << endl;
  return 0;
}
