#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> a[2005];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1, [](pair<int, int> x, pair<int, int> y) {
    if (x.first == y.first) return x.second < y.second;
    return x.first > y.first;
  });
  sort(a + 1, a + k + 1, [](pair<int, int> x, pair<int, int> y) {
    if (x.second == y.second) return x.first < y.first;
    return x.second < y.second;
  });
  int sum = 0;
  for (int i = 1; i <= k; i++) sum += a[i].first;
  cout << sum << '\n';
  int pi = 0;
  for (int i = 1; i <= k; i++) {
    if (i > 1) cout << ' ';
    if (i != k)
      cout << a[i].second - pi;
    else
      cout << n - pi << '\n';
    pi = a[i].second;
  }
  return 0;
}
