#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ddx[8] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[8] = {1, -1, 1, 0, -1, 1, 0, -1};
long long MOD = 1000000000;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / GCD(a, b));
}
bool OOB(long long x, long long y, long long N, long long M) {
  return 0 > x || x >= N || 0 > y || y >= M;
}
struct p {
  int x;
  int y;
};
p a[20000];
bool cmp(const p &t1, const p &t2) { return (t1.x > t2.x); }
int b[20000] = {0};
int c[20000] = {0};
int main() {
  int sum = 0;
  int i, j, k;
  int n;
  int t;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].x);
    a[i].y = i;
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= k; i++) {
    sum = sum + a[i].x;
    b[a[i].y] = 1;
  }
  int js = 0;
  int wz = 1;
  int pp = 1;
  while (wz <= n) {
    if (b[wz] == 1) {
      js++;
      c[pp] = js;
      pp++;
      js = 0;
    } else if (b[wz] == 0)
      js++;
    wz++;
  }
  int r;
  r = n;
  while (b[r] == 0) r--;
  c[k] = c[k] + n - r;
  cout << (sum) << '\n';
  for (int i = 1; i <= k - 1; i++) cout << (c[i]) << ' ';
  cout << (c[k]) << '\n';
  return 0;
}
