#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int s[maxn];
struct node {
  int a, b;
} a[maxn];
bool cmp(node a, node b) { return a.a > b.a; }
int main() {
  int n, k, l = 1, ans = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].a);
    a[i].b = i;
  }
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= k; i++) {
    ans += a[i].a;
    s[i] = a[i].b;
  }
  s[0] = 0;
  sort(s, s + k + 1);
  cout << ans << endl;
  for (int i = 0; i < maxn; i++)
    ;
  for (int i = 1; i <= k; i++) {
    if (i == k)
      cout << n - s[i - 1];
    else
      cout << s[i] - s[i - 1] << " ";
  }
}
