#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int ar[n + 5];
  int br[n + 5];
  int mark[200005];
  memset(mark, 0, sizeof mark);
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    br[i] = ar[i];
  }
  sort(br, br + n, greater<int>());
  int sum = 0;
  int cr[n + 5];
  int c = 0;
  for (int i = 0; i < k; i++) {
    sum += br[i];
    for (int j = 0; j < n; j++) {
      if (br[i] == ar[j]) {
        ar[j] = 0;
        cr[c++] = j;
      }
    }
  }
  sort(cr, cr + k);
  cout << sum << endl;
  if (k == 1)
    cout << n << endl;
  else {
    for (int i = 0; i < k; i++) {
      if (i == 0) {
        cout << cr[i] + 1 << " ";
      } else if (i == k - 1) {
        int p = cr[i] - cr[i - 1];
        p += n - cr[i] - 1;
        cout << p << endl;
      } else {
        cout << cr[i] - cr[i - 1] << " ";
      }
    }
  }
  return 0;
}
