#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long M = 500006;
const int mod = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    vector<int> orig(v);
    sort(v.rbegin(), v.rend());
    unordered_multiset<int> hash;
    int sum = 0;
    for (int i = 0; i < k; i++) hash.insert(v[i]), sum += v[i];
    cout << sum << "\n";
    int prev = -1;
    vector<int> ans;
    int m = 0;
    for (int i = 0; i < n; i++) {
      auto it = hash.find(orig[i]);
      if (it != hash.end()) {
        if (m == (k - 1)) break;
        ans.push_back(i - prev);
        m++;
        prev = i;
        hash.erase(it);
      }
    }
    ans.push_back(n - 1 - prev);
    for (auto x : ans) cout << x << " ";
  }
  return 0;
}
