CF120C.Winnie-the-Pooh and honey

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are n jars of honey lined up in front of Winnie-the-Pooh, jar number i contains a__i kilos of honey. Winnie-the-Pooh eats the honey like that: each time he chooses a jar containing most honey. If the jar has less that k kilos of honey or if Winnie-the-Pooh has already eaten from it three times, he gives the jar to Piglet. Otherwise he eats exactly k kilos of honey from the jar and puts it back. Winnie does so until he gives all jars to the Piglet. Count how much honey Piglet will overall get after Winnie satisfies his hunger.

众所周知,小熊维尼特别喜爱蜂蜜。有一天,他和小猪发现兔子最近得到了大量这种甜美又健康的零食。可想而知,维尼和小猪便请求到兔子家做客。于是,维尼面前整齐地摆放着 nn 罐蜂蜜,其中第 ii 罐含有 aia_i 千克蜂蜜。维尼吃蜂蜜的方式如下:每次他都选择当前蜂蜜量最多的那一罐。如果该罐蜂蜜少于 kk 千克,或者维尼已经从中吃过三次,他就把这罐蜂蜜交给小猪;否则,他恰好从中吃掉 kk 千克蜂蜜,然后将该罐放回原处。维尼持续这样做,直到所有罐子都被交给小猪为止。请计算:在维尼满足自己的食欲后,小猪总共能得到多少千克蜂蜜?

输入格式

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100). The second line contains n integers _a_1, _a_2, ..., a__n, separated by spaces (1 ≤ a__i ≤ 100).

第一行包含两个整数 nn 和 kk(1 ≤ n ≤ 1001 \le n \le 100,1 ≤ k ≤ 1001 \le k \le 100)。第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n,以空格分隔(1 ≤ ai ≤ 1001 \le a_i \le 100)。

输出格式

Print a single number — how many kilos of honey gets Piglet.

输出一个数字——小猪能获得多少千克蜂蜜。

输入输出样例

  • 输入#1

    3 3
    15 8 10

    输出#1

    9

输入解题思路,AI测评打分。不知道怎么写?

首页