#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
struct node {
  int x, y;
  bool operator<(const node &b) const { return x > b.x; }
} node[maxn];
int n, k;
int vec[maxn];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &node[i].x);
    node[i].y = i;
  }
  long long ans = 0;
  sort(node + 1, node + n + 1);
  int cnt = 0;
  for (int i = 1; i <= k; ++i) vec[++cnt] = node[i].y, ans += node[i].x;
  cout << ans << endl;
  sort(vec + 1, vec + k + 1);
  vec[0] = 0;
  for (int i = 1; i <= k; ++i) {
    if (i == k)
      printf("%d ", n - vec[i - 1]);
    else
      printf("%d ", vec[i] - vec[i - 1]);
  }
  return 0;
}
