#include<bits/stdc++.h>
#define ll long long
using namespace std;
int f[5005][10005], ans[5005], pre[5005][10005], a[5005];
int main() {
int n, m, i, j, k, s = 0;
cin >> n >> m;
memset(f, 60, sizeof(f));
f[0][0] = 0;
// Input values for array 'a'
for (i = 1; i <= n; i++) {
cin >> a[i];
for (j = 0; j <= 10000; j++) {
if (f[i - 1][j] <= s) {
int tp = m + j - s + f[i - 1][j];
for (k = 0; k <= tp && 2 * k <= a[i]; k++) {
int o = j + (a[i] - k) / 10;
if (f[i][o] > f[i - 1][j] + a[i] - k) {
f[i][o] = f[i - 1][j] + a[i] - k;
pre[i][o] = k;
}
}
}
}
s += a[i];
}
// Finding the result
int res = 0;
for (i = 0; i <= 10000; i++) {
if (f[n][i] < f[n][res]) {
res = i;
}
}
cout << f[n][res] << endl;
for (i = n; i; i--) {
ans[i] = pre[i][res];
res -= (a[i] - ans[i]) / 10;
}
for (i = 1; i <= n; i++) {
cout << ans[i] << ' ';
}
return 0;
}
620A - Professor GukiZ's Robot | 1342A - Road To Zero |
1520A - Do Not Be Distracted | 352A - Jeff and Digits |
1327A - Sum of Odd Integers | 1276A - As Simple as One and Two |
812C - Sagheer and Nubian Market | 272A - Dima and Friends |
1352C - K-th Not Divisible by n | 545C - Woodcutters |
1528B - Kavi on Pairing Duty | 339B - Xenia and Ringroad |
189A - Cut Ribbon | 1182A - Filling Shapes |
82A - Double Cola | 45A - Codecraft III |
1242A - Tile Painting | 1663E - Are You Safe |
1663D - Is it rated - 3 | 1311A - Add Odd or Subtract Even |
977F - Consecutive Subsequence | 939A - Love Triangle |
755A - PolandBall and Hypothesis | 760B - Frodo and pillows |
1006A - Adjacent Replacements | 1195C - Basketball Exercise |
1206A - Choose Two Numbers | 1438B - Valerii Against Everyone |
822A - I'm bored with life | 9A - Die Roll |