• Cormen — The Best Friend Of a Man CodeForces 732B


    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 = 5 and 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 nintegers 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 integers b1, b2, ..., bn (bi ≥ ai), where bimeans the total number of walks with the dog on the i-th day.

    Input

    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.

    Output

    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.

    Examples

    Input
    3 5
    2 0 1
    Output
    4
    2 3 2
    Input
    3 1
    0 0 0
    Output
    1
    0 1 0
    Input
    4 6
    2 4 3 5
    Output
    0
    2 4 3 5

    没错,就是遛狗,emmmmm。题目所述就是一个人有一个狗“朋友”,每两天的散步次数总和为K;输入n天已经走了的次数,输出还需要多走几次和每天应该的次数。
    其实就是后一天加前一天的次数大于等于K:
    #include<iostream>
    using namespace std;
    int main()
    {
        int a,b;
        cin>>a>>b;
        int arr[500];
        int sum=0;
        cin>>arr[0];
        for(int i=1;i<a;i++)
        {
            cin>>arr[i];
            if(arr[i]+arr[i-1]<b)
            {
                sum+=b-arr[i]-arr[i-1];
                arr[i]=b-arr[i-1];
            }
        }
        cout<<sum<<endl;
        for(int i=0;i<a;i++)
        {
            if(i!=0)
                cout<<' ';
            cout<<arr[i];
        }
    }
  • 相关阅读:
    python爬虫 -掘金
    python 爬取简书评论
    python爬取知乎评论
    python 爬取链家
    python爬虫获取下一页
    python正则找到字符串里面的数字
    faker切换user-agent
    python 爬虫可视化函数,可以先看看要爬取的数据是否存在
    acwing 471. 棋盘 解题记录
    ACWING 95 费解的开关 解题记录
  • 原文地址:https://www.cnblogs.com/mozheaishang/p/10004070.html
Copyright © 2020-2023  润新知