#include <bits/stdc++.h>
using namespace std;
int n, i, b[2000], c[2000], m, j, s = 0;
int main() {
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> b[i];
    c[i] = i + 1;
  }
  for (i = 0; i < m; i++)
    for (j = i + 1; j < n; j++)
      if (b[j] > b[i]) {
        swap(b[j], b[i]);
        swap(c[j], c[i]);
      }
  for (i = 0; i < m; i++)
    for (j = i + 1; j < m; j++)
      if (c[j] < c[i]) {
        swap(c[j], c[i]);
        swap(b[j], b[i]);
      }
  for (i = 0; i < m; i++) s += b[i];
  cout << s << endl;
  if (m == 1) {
    cout << n;
    return 0;
  }
  cout << c[0] << " ";
  for (i = 1; i < m - 1; i++) cout << c[i] - c[i - 1] << " ";
  cout << n - c[--i];
  return 0;
}
