#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
struct num {
  int x, y;
} a[maxn];
int cmp(num a, num b) { return a.x > b.x; }
int cmp2(num a, num b) { return a.y < b.y; }
int main() {
  int n, k, ans = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x;
    a[i].y = i;
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= k; i++) ans += a[i].x;
  cout << ans << endl;
  sort(a + 1, a + k + 1, cmp2);
  if (k == 1) {
    cout << n << endl;
    return 0;
  } else {
    for (int i = 1; i <= k; i++) {
      if (i == 1)
        cout << a[i].y;
      else if (i == k)
        cout << ' ' << n - a[k - 1].y;
      else
        cout << ' ' << a[i].y - a[i - 1].y;
    }
  }
  return 0;
}
