#include <bits/stdc++.h>
const int maxn = 2e5 + 100;
const int mod = 200907;
using namespace std;
struct node {
  int x, i;
};
int cmp(node a, node b) { return a.i <= b.i; }
int cmp1(node a, node b) { return a.x > b.x; }
int main() {
  node a[2005];
  int n, k, x;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[i].x = x;
    a[i].i = i;
  }
  sort(a + 1, a + n + 1, cmp1);
  int sum = 0, t = k;
  for (int i = 1; i <= t; i++) sum += a[i].x;
  sort(a + 1, a + k + 1, cmp);
  cout << sum << endl;
  for (int i = 1; i <= k; i++) {
    if (!i)
      cout << a[i].i << " ";
    else if (i == k)
      cout << n - a[i - 1].i << endl;
    else
      cout << a[i].i - a[i - 1].i << " ";
  }
  return 0;
}
