#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> p1, pair<int, int> p2) { return p1.first > p2.first; }
int main() {
  int n, k;
  cin >> n >> k;
  pair<int, int> p[n];
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    p[i] = {x, i};
  }
  int ans = 0;
  vector<int> v;
  sort(p, p + n, comp);
  for (int i = 0; i < k; i++) {
    ans += p[i].first;
    v.push_back(p[i].second);
  }
  cout << ans << endl;
  sort(v.begin(), v.end());
  for (auto it = v.begin(); it != v.end(); it++) {
    if (v.begin() == v.end() - 1) {
      cout << n << endl;
      break;
    }
    if (it == v.begin())
      cout << *it + 1 << " ";
    else if (it + 1 == v.end())
      cout << n - 1 - *(it - 1) << " ";
    else
      cout << *it - *(it - 1) << " ";
  }
  cout << endl;
}
