#include <bits/stdc++.h>
int n, k, sum;
std::vector<std::pair<int, int>> V;
std::vector<int> answer;
int event[2018];
bool comp(std::pair<int, int> a, std::pair<int, int> b) {
  if (a.first != b.first) return a.first > b.first;
  return a.second > b.second;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    V.push_back(std::make_pair(p, i));
  }
  sort(V.begin(), V.end(), comp);
  for (int i = V.size() - 1; i >= k; i--) {
    V.pop_back();
  }
  for (auto&& i : V) {
    sum += i.first;
    event[i.second]++;
  }
  printf("%d\n", sum);
  int prev_state = 0;
  for (int i = 0; i < n; i++) {
    if (event[i] > 0) {
      answer.push_back(i - prev_state + 1);
      prev_state = i + 1;
      event[i]--;
      if (i == n - 1) answer.push_back(0);
    } else if (i == n - 1)
      answer.push_back(i - prev_state + 1);
  }
  answer[answer.size() - 2] += answer[answer.size() - 1];
  for (int i = 0; i < answer.size() - 1; i++) {
    printf("%d ", answer[i]);
  }
}
