Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk.
Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5and yesterday Polycarp went for a walk with Cormen 2 times, today he has to go for a walk at least 3 times.
Polycarp analysed all his affairs over the next n days and made a sequence of n integers a1, a2, ..., an, where ai is the number of times Polycarp will walk with the dog on the i-th day while doing all his affairs (for example, he has to go to a shop, throw out the trash, etc.).
Help Polycarp determine the minimum number of walks he needs to do additionaly in the next n days so that Cormen will feel good during all the n days. You can assume that on the day before the first day and on the day after the n-th day Polycarp will go for a walk with Cormen exactly k times.
Write a program that will find the minumum number of additional walks and the appropriate schedule — the sequence of integersb1, b2, ..., bn (bi ≥ ai), where bi means the total number of walks with the dog on the i-th day.
The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days.
The second line contains integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned.
In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days.
In the second line print n integers b1, b2, ..., bn, where bi — the total number of walks on the i-th day according to the found solutions (ai ≤ bi for all i from 1 to n). If there are multiple solutions, print any of them.
3 5 2 0 1
4 2 3 2
3 1 0 0 0
1 0 1 0
4 6 2 4 3 5
0 2 4 3 5
题意:
带着宠物轧马路,连续的两天出去的时间和不能低于给定的 K,
问对于给出的计划方案数还需要额外增加多少时间可以满足。
思路:
感觉水水的一题,昨晚瞄了一眼,渣渣英语没做,今天竟然 1A 了,,,,,,
Ac code:
#include<stdio.h>
#include<cstring>
#include<algorithm>
#define AC main()
using namespace std;
const int MYDD = 1103;
int AC {
int n, k, a[MYDD], b[MYDD], ans = 0;
scanf("%d %d", &n, &k);
for(int j = 1; j <= n; j++) {
scanf("%d", &a[j]);
b[1] = a[1];
}
for(int j = 2; j <= n; j++) {
b[j] = a[j];
if(a[j] + a[j-1] < k) {
b[j] = k - a[j-1];
}
ans += b[j] - a[j];
a[j] = b[j];
}
printf("%d\n", ans);
for(int j = 1; j <= n; j++) printf("%d ", b[j]);
return 0;
}