#include <bits/stdc++.h>
using namespace std;
bool mycomp(pair<int, int> p1, pair<int, int> p2) {
  if (p1.first != p2.first) {
    return p1.first > p2.first;
  } else {
    return p1.second < p2.second;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    pair<int, int> arr[n];
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      arr[i] = make_pair(a, i);
    }
    sort(arr, arr + n, mycomp);
    int ans = 0;
    for (int i = 0; i < k; i++) {
      ans += arr[i].first;
    }
    cout << ans << endl;
    vector<int> v;
    for (int i = 0; i < k; i++) {
      v.push_back(arr[i].second);
    }
    sort(v.begin(), v.end());
    int m = v.size();
    if (v.size() == 1) {
      cout << n << endl;
      return 0;
    }
    for (int i = 0; i < m; i++) {
      if (i != 0 and i != (m - 1)) {
        ans = v[i] - v[i - 1];
        cout << ans << " ";
      } else if (i == 0) {
        cout << v[i] + 1 << " ";
      } else if (i == (m - 1)) {
        ans = n - v[i - 1] - 1;
        cout << ans << endl;
      }
    }
  }
  return 0;
}
