#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x;
  scanf("%d %d", &n, &m);
  vector<pair<int, int> > p;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    p.push_back({-x, i + 1});
  }
  sort(p.begin(), p.end());
  long long ans = 0;
  vector<int> v;
  for (int i = 0; i < m; ++i) {
    ans -= p[i].first;
    v.push_back(p[i].second);
  }
  printf("%lld\n", ans);
  sort(v.begin(), v.end());
  int l = 0;
  for (int i = 0; i < v.size() - 1; i++) {
    printf("%lld ", v[i] - l);
    l = v[i];
  }
  printf("%d\n", n - l);
  return 0;
}
