#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> A(n);
  for (int i = 0; i < n; i++) cin >> A[i].first, A[i].second = i + 1;
  sort(A.begin(), A.end());
  vector<int> O(k);
  int sum = 0;
  for (int i = 0; i < k; i++)
    O[i] = A[n - i - 1].second, sum += A[n - i - 1].first;
  sort(O.begin(), O.end());
  cout << sum << "\n";
  if (k != 1) {
    cout << O[0];
    for (int i = 1; i < k - 1; i++) cout << " " << O[i] - O[i - 1];
    cout << " " << n - O[k - 2];
  } else
    cout << n;
}
