#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<int, int> num;
int n, k, sum, cnt, br, a[N], b[N];
vector<int> arr;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + n, greater<int>());
  for (int i = 0; i < k; i++) {
    sum += a[i];
    num[a[i]]++;
  }
  arr.push_back(-1);
  cout << sum << endl;
  int left = n;
  for (int i = 0; i < n; i++) {
    if (num.count(b[i])) {
      if (num[b[i]] != 0) {
        if (k == 1)
          arr.push_back(n - 1);
        else
          arr.push_back(i);
        num[b[i]]--;
        k--;
      }
    }
  }
  for (int i = 1; i < arr.size(); i++) cout << arr[i] - arr[i - 1] << " ";
  return 0;
}
