#include <bits/stdc++.h>
using namespace std;
struct st {
  long long in, v;
};
st a[500005];
bool cmp(st i, st j) {
  if (i.v == j.v) return i.in > j.in;
  return i.v < j.v;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int i;
  int ans, n, m, x, y;
  while (cin >> n >> x) {
    for (i = 0; i < n; i++) {
      cin >> a[i].v;
      a[i].in = i;
    }
    sort(a, a + n, cmp);
    vector<long long> ans;
    long long sum = 0;
    for (i = n - 1; i >= n - x; i--) {
      sum += a[i].v;
      ans.push_back(a[i].in + 1);
    }
    cout << sum << endl;
    sort(ans.begin(), ans.end());
    if (x == 1) {
      cout << n << endl;
    } else {
      for (i = 0; i < ans.size(); i++) {
        if (i != 0 && i != x - 1)
          cout << " " << ans[i] - ans[i - 1];
        else if (i != x - 1)
          cout << ans[i];
      }
      cout << " " << n - ans[x - 2] << endl;
    }
  }
}
