#include <bits/stdc++.h>
using namespace std;
int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string itos(long long i) {
  string s = "";
  while (i) {
    s += char(i % 10 + '0');
    i /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
long long stoi(string &s) {
  long long tot = 0;
  for (int i = (int)s.length() - 1, j = 1; i >= 0; i--, j *= 10) {
    tot += j * (s[i] + '0');
  }
  return tot;
}
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
long long pwr(long long base, long long p, long long mod = 1000000007) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % 1000000007;
    base = (base * base) % 1000000007;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b * 1LL) / gcd(a, b); }
const int N = 6e5 + 5;
const int LN = 30;
int n, k;
int ans = 0;
pair<int, int> a[N];
int vis[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  clock_t clk;
  clk = clock();
  cin >> n >> k;
  for (int i = (1); i <= (n); ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1);
  for (int i = (1); i <= (k); ++i) {
    int num = a[n - i + 1].first;
    int idx = a[n - i + 1].second;
    vis[idx] = 1;
    ans += num;
  }
  if (k == 1) {
    cout << ans << "\n";
    cout << n;
    return 0;
  }
  int cnt = 0;
  int f = 0;
  vector<int> v;
  int inc;
  for (int i = (1); i <= (n); ++i) {
    if (vis[i]) {
      if (!f) inc = i - 1;
      cnt = 1;
      i++;
      while (!vis[i] && i <= n) {
        ++cnt;
        ++i;
      }
      if (i > n)
        v.push_back(cnt);
      else {
        v.push_back(cnt);
        i--;
      }
      f = 1;
    }
  }
  v[0] += inc;
  cout << ans << endl;
  for (int i = 0; i < (v.size()); ++i) cout << v[i] << " ";
  clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
       << "\n";
  return 0;
}
