#include <bits/stdc++.h>
using namespace std;
bool cmp1(pair<int, int> &x, pair<int, int> &y) { return x.first > y.first; }
bool cmp2(pair<int, int> &x, pair<int, int> &y) { return x.second < y.second; }
int main() {
  int m, n;
  while (cin >> m >> n) {
    vector<pair<int, int> > v(m);
    for (int i = 0; i < m; ++i) {
      cin >> v[i].first;
      v[i].second = i + 1;
    }
    sort(v.begin(), v.end(), cmp1);
    int maxv = 0;
    vector<pair<int, int> > ans;
    for (int i = 0; i < n; ++i) {
      ans.push_back(v[i]);
      maxv += v[i].first;
    }
    sort(ans.begin(), ans.end(), cmp2);
    cout << maxv << endl;
    if (n == 1) {
      cout << v.size() << endl;
    } else {
      for (int i = 0; i < n; ++i) {
        if (i == 0)
          cout << ans[i].second << " ";
        else if (i == n - 1)
          cout << v.size() - ans[i - 1].second << endl;
        else
          cout << ans[i].second - ans[i - 1].second << " ";
      }
    }
  }
  return 0;
}
