#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 100;
int a[maxn], b[maxn], c[maxn], vis[maxn];
int main() {
  int n, m;
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    sort(a, a + n);
    int cnt = 0, k = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (cnt == m)
        break;
      else {
        k += a[i];
        vis[a[i]]++;
      }
      cnt++;
    }
    int j = 0, sum = 0;
    for (int i = 0; i < n; i++) {
      sum++;
      if (vis[b[i]] > 0) {
        vis[b[i]]--;
        if (j == m - 1) sum += n - i - 1;
        c[j++] = sum;
        sum = 0;
      }
    }
    cout << k << endl;
    for (int i = 0; i < j; i++) cout << c[i] << ' ';
    cout << endl;
  }
  return 0;
}
