#include <bits/stdc++.h>
using namespace std;
long long n, k, ans, tem;
struct node {
  long long w, p;
};
bool cmp(node n1, node n2) { return n1.w < n2.w; }
node a[2005], b[2005];
long long c[2005], dp[2005];
queue<long long> q;
int main() {
  cin >> n >> k;
  ans = 0;
  tem = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i].w;
    b[i].w = a[i].w;
    a[i].p = i;
    b[i].p = i;
  }
  sort(b, b + n, cmp);
  for (int i = n - 1; i >= n - k; i--) ans += b[i].w;
  for (int i = n - k; i <= n - 1; i++) {
    q.push(b[i].p);
  }
  for (int i = 0; i < k; i++) {
    int t = q.front();
    c[i] = t;
    q.pop();
  }
  sort(c, c + k);
  cout << ans << endl;
  if (k == 1)
    cout << n << endl;
  else {
    cout << c[1] << " ";
    for (int i = 1; i < k - 1; i++) {
      cout << c[i + 1] - c[i] << " ";
    }
    cout << n - c[k - 1] << endl;
  }
  return 0;
}
