#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, i, j, k, l, m, n, p, q, r, s = 0, ans = 0, a, b, c, d, x, y;
  cin >> n >> k;
  long long A[n + 10];
  priority_queue<pair<long long, long long> > pq;
  map<long long, long long> mp;
  for (i = 0; i < n; i++) {
    cin >> A[i];
    pq.push(make_pair(A[i], i));
    mp[A[i]]++;
  }
  map<long long, long long> mp1;
  long long k1 = k;
  while (k--) {
    pair<long long, long long> p1 = pq.top();
    pq.pop();
    p = p1.first;
    mp1[p]++;
    s += p;
  }
  cout << s << endl;
  j = 0;
  p = 0;
  for (i = 0; i < n; i++) {
    if (p == k1 - 1) {
      cout << n - j << endl;
      break;
    }
    if (mp1[A[i]] > 0) {
      mp1[A[i]]--;
      cout << i - j + 1 << " ";
      j = i + 1;
      p++;
    }
  }
}
