#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long LINF = 4611686018427387903;
const int dir4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir8[8][2] = {{1, 0}, {0, 1},   {-1, 0}, {0, -1},
                        {1, 1}, {-1, -1}, {1, -1}, {-1, 1}};
const int dir63[6][3] = {{0, 0, 1},  {0, 0, -1}, {0, 1, 0},
                         {0, -1, 0}, {1, 0, 0},  {-1, 0, 0}};
const int daym[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
                         {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int n, m;
struct Node {
  int num;
  bool f;
} a[2222];
struct Node2 {
  int idx, num;
} b[2222];
bool cmp(Node2 a, Node2 b) { return a.num > b.num; }
int main() {
  int sum = 0, imax = -0x3f3f3f3f;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i].num);
    b[i].num = a[i].num;
    b[i].idx = i;
    sum += a[i].num;
    imax = max(imax, a[i].num);
  }
  if (m == n) {
    printf("%d\n", sum);
    for (int i = 0; i < n; i++) {
      if (i) printf(" ");
      printf("1");
    }
  } else if (m == 1) {
    printf("%d\n", imax);
    printf("%d\n", n);
  } else {
    int cnt = 0, flag = m;
    sum = 0;
    sort(b, b + n, cmp);
    for (int i = 0; i < m; i++) {
      a[b[i].idx].f = 1;
      sum += b[i].num;
    }
    printf("%d\n", sum);
    for (int i = 0; i < n; i++) {
      cnt++;
      if (a[i].f) {
        printf("%d ", cnt);
        cnt = 0;
        flag--;
        if (flag == 1) {
          for (int j = i + 1; j < n; j++) {
            cnt++;
          }
          printf("%d\n", cnt);
          break;
        }
      }
    }
  }
  return 0;
}
