#include <bits/stdc++.h>
using namespace std;
int hs[2005], a[2005];
vector<pair<int, int> > v;
int main() {
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    v.push_back({a[i], i});
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (cnt >= k) break;
    hs[v[i].second] = 1;
    ans += v[i].first;
    ++cnt;
  }
  cnt = 0;
  cout << ans << endl;
  int ret = 0, pre = -1;
  for (int i = 0; i < n; i++) {
    if (hs[i]) {
      if (cnt < k - 1)
        cout << ret + 1 << " ";
      else
        cout << n - pre - 1;
      ret = 0, cnt++, pre = i;
    } else
      ret++;
  }
  return 0;
}
