水题CodeForces 120C

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

input
input.txt
output
output.txt

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 ai 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.

Input

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100). The second line contains n integers a1a2, ..., an, separated by spaces (1 ≤ ai ≤ 100).

Output

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

Sample Input

Input
3 3
15 8 10
Output
9


#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,k;
int a[110];
scanf("%d%d",&n,&k);
int i,j;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>=3*k)
a[i]-=3*k;
else if(a[i]>=2*k)
a[i]-=2*k;
else if(a[i]>=k)
a[i]-=k;

}
int sum=0;
for(i=0;i<n;i++)
{
sum+=a[i];
}
printf("%d\n",sum);

return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值