#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int k, sz, ans, b[500005];
pair<int, int> s[500005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout.precision(6);
  cerr.precision(7);
  ;
  cin >> sz >> k;
  for (int i = 0; i < sz; i++) {
    cin >> s[i].first;
    s[i].second = i;
  }
  sort(s, s + sz);
  for (int i = sz - k; i < sz; i++) {
    ans += s[i].first;
    b[i - sz + k] = s[i].second;
  }
  sort(b, b + k);
  cout << ans << "\n";
  for (int i = 0; i < k - 1; i++)
    cout << (i ? b[i] - b[i - 1] : b[0] + 1) << " ";
  cout << (k > 1 ? sz - 1 - b[k - 2] : sz);
  return 0;
}
