#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> a(n), b, c, d(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    d = a;
    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());
    long long sum = 0;
    for (int i = 0; i < k; i++) {
      c.push_back(d[i]);
      sum += d[i];
      b.push_back(d[i]);
    }
    c.clear();
    cout << sum << "\n";
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
      bool ok = false;
      for (int j = 0; j < b.size(); j++)
        if (b[j] == a[i]) {
          b[j] = -1;
          ok = true;
          break;
        }
      if (ok) {
        cnt++;
        c.push_back(cnt);
        cnt = 0;
      } else
        cnt++;
    }
    for (int i = 0; i < c.size(); i++)
      if (i == c.size() - 1)
        cout << c[i] + cnt;
      else
        cout << c[i] << " ";
  }
}
