#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 6, MX = 1e9 + 6;
int i, j, cnt;
long long a[M], b[M], arr[M];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> a[i];
  ;
  set<int> idx[2006];
  for (i = 1; i <= n; i++) {
    idx[a[i]].insert(i);
  }
  sort(a + 1, a + n + 1, greater<int>());
  vector<int> v;
  int sum = 0;
  v.push_back(0);
  for (i = 1; i <= k; i++) {
    sum += a[i];
    auto it = idx[a[i]].begin();
    v.push_back(*it);
    idx[a[i]].erase(it);
  }
  sort(v.begin(), v.end());
  cout << sum << endl;
  for (i = 0; i < k - 1; i++) {
    cout << v[i + 1] - v[i] << " ";
  }
  cout << n - v[k - 1];
}
