#include <bits/stdc++.h>
using namespace std;
struct NUM {
  int num;
  int index;
} N[1000000];
bool cmp(NUM a, NUM b) {
  if (a.num == b.num) {
    return a.index < b.index;
  }
  return a.num > b.num;
}
int main() {
  int n, k;
  cin >> n;
  cin >> k;
  int ans = 0;
  int ans1[2005];
  for (int i = 1; i <= n; i++) {
    cin >> N[i].num;
    N[i].index = i;
  }
  sort(N + 1, N + n + 1, cmp);
  for (int i = 1; i <= k; i++) {
    ans = ans + N[i].num;
    ans1[i] = N[i].index;
  }
  ans1[0] = 0;
  int ans2 = 0;
  sort(ans1, ans1 + k + 1);
  cout << ans << endl;
  for (int i = 1; i < k; i++) {
    cout << ans1[i] - ans1[i - 1] << " ";
    ans2 = ans2 + ans1[i] - ans1[i - 1];
  }
  cout << n - ans2 << endl;
  return 0;
}
