rt
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
int a[N], n, m;
bool check(int x)
{
int now = 1;
int ans = 0;
for(int i = 1; i <= m; i++)
{
ans /= 2;
while(ans < x)
{
ans += a[now];
if(now > n) return 0;
now++;
}
}
return 1;
}
void prans(int x)
{
int now = 1;
int ans = 0;
for(int i = 1; i <= m; i++)
{
ans /= 2;
while(ans < x)
{
cout << i << "\n";
ans += a[now++];
if(now == n + 1) return ;
}
// cout << ans << " ";
}
for(int i = now; i <= n; i++) cout << m << endl;
}
signed main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
int l = 0, r = 1e18;
// cout << check(24) << endl;
while(l <= r)
{
int mid = (l + r) >> 1;
if(l == r) break;
if(check(mid))
{
l = mid + 1;
}
else
{
r = mid - 1;
}
// cout << l << " " << r << endl;
}
cout << l - 1 << "\n";
prans(l - 1);
return 0;
}