#include <bits/stdc++.h>
using namespace std;
int n, a[10000], k, mx, ii, jj, b[10000], ans;
int main() {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int j = 0; j < k; j++) {
    mx = -1;
    for (int i = 0; i < n; i++) {
      if (mx < a[i]) mx = a[i], ii = i;
    }
    ans += mx;
    a[ii] = -1;
    b[jj++] = ii + 1;
  }
  cout << ans << endl;
  sort(b, b + jj);
  for (int i = 0; i < jj; i++) {
    if (i == jj - 1)
      cout << n - b[i - 1] << " ";
    else if (i)
      cout << b[i] - b[i - 1] << " ";
    else
      cout << b[i] << " ";
  }
}
