#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
using namespace std;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcount(s);
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const int MAXN = 2100;
const int MOD = 1e9 + 7;
const long long MAXV = 1e6;
const double eps = 1e-12;
const long long INF = 1e16;
inline string toStr(long long x) {
  string tmp = "";
  do tmp = char(x % 10 + '0') + tmp;
  while (x /= 10);
  return tmp;
}
inline long long toInt(string s) {
  long long res = 0;
  for (auto x : s) res = res * 10 + x - '0';
  return res;
}
inline string toBinStr(long long x) {
  string res = "";
  do res = (x % 2 ? "1" : "0") + res;
  while (x >>= 1LL);
  return res;
}
long long rnd(int k) {
  if (!k) return rand() % MAXV + 1;
  long long t = rand() % MAXV + 1;
  return (rand() % t) + (MAXV - t);
}
long long random_gen(int sign) {
  long long x = rnd(rand() % 2);
  long long s = rand() % 2;
  s = !s ? 1 : -1;
  return sign == 1 ? x : sign == -1 ? -x : s * x;
}
inline void debugArray(int a[], int n) {
  cerr << "array = ";
  for (int i = 0; i < n; ++i) cerr << a[i] << " ";
  cerr << "\n";
}
vector<int> a;
vector<pair<int, int>> b;
int main() {
  int n, k;
  cin >> n >> k;
  a.resize(n), b.resize(n);
  for (int i = 0, _a = (n); i < _a; ++i) scanf("%d", &a[i]), b[i] = {a[i], i};
  sort(b.begin(), end(b));
  reverse(b.begin(), b.end());
  if (k == 1)
    return !printf("%d\n%d", *max_element(begin(a), end(a)), n);
  else {
    int sum = 0;
    vector<int> good;
    for (int i = 0, _a = (k); i < _a; ++i)
      good.push_back(b[i].second), sum += b[i].first;
    sort(begin(good), end(good));
    vector<int> res;
    res.push_back(good[0] + 1);
    for (int i = (1), _b = (good.size() - 2); i <= _b; i++)
      res.push_back(good[i] - good[i - 1]);
    res.push_back(n - 1 - good[good.size() - 2]);
    printf("%d\n", sum);
    for (auto x : res) printf("%d ", x);
  }
}
