#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v;
  long long int a;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    v.push_back(make_pair(a, i));
  }
  sort(v.begin(), v.end());
  long long int ans = 0;
  vector<int> l;
  l.push_back(0);
  for (int i = n - 1; i >= n - k; i--) {
    ans = ans + v[i].first;
    l.push_back(v[i].second);
  }
  sort(l.begin(), l.end());
  cout << ans << endl;
  for (int i = 1; i < k; i++) {
    cout << l[i] - l[i - 1] << " ";
  }
  cout << n - l[k - 1];
}
