#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> p[10001];
pair<long long, long long> p1[10001];
long long a[10001], n, b, c, v, x, y, i, j, k, s;
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> p[i].first;
    p[i].second = i;
  }
  sort(p + 1, p + n + 1);
  if (k == 1) {
    cout << p[n].first << endl;
    cout << n;
    return 0;
  }
  for (i = n; i >= n - k + 1; i--) {
    p1[i].first = p[i].second;
    p1[i].second = p[i].first;
  }
  sort(p1 + 1, p1 + n + 1);
  j = 0;
  for (i = n - k + 1; i <= n; i++) {
    s += p1[i].second;
  }
  cout << s << endl;
  for (i = n - k + 1; i <= n - 1; i++) {
    cout << p1[i].first - j << " ";
    j = p1[i].first;
  }
  cout << n - p1[n].first + p1[n].first - j;
}
