#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int arr[N];
vector<pair<int, int>> b;
bool comp(pair<int, int> x, pair<int, int> y) { return x.second < y.second; }
void solve() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    b.push_back({arr[i], i + 1});
  }
  sort(b.begin(), b.end());
  if (k > 1) {
    long long ans = 0;
    for (int i = n - 1; i > n - 1 - k; i--) {
      ans += b[i].first;
    }
    cout << ans << endl;
    sort(b.begin() + n - k, b.end(), comp);
    for (int i = n - k; i < n; i++) {
      if (i == n - k)
        cout << b[i].second << " ";
      else if (i != n - 1)
        cout << b[i].second - b[i - 1].second << " ";
      else
        cout << n - b[i - 1].second << " ";
    }
  } else
    cout << b[n - 1].first << "\n" << n << endl;
}
int main() {
  ios_base::sync_with_stdio(), cout.tie(NULL), cin.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
