Anastasia and pebbles

Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.

She has only two pockets. She can put at mostk pebbles in each pocket at the same time. There aren different pebble types in the park, and there arewi pebbles of thei-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.

Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.

Input

The first line contains two integers n andk (1 ≤ n ≤ 105,1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.

The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.

Output

The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.

Example
Input
3 2
2 3 4
Output
3
Input
5 4
3 1 8 9 7
Output
5
Note

In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.

Optimal sequence of actions in the second sample case:

  • In the first day Anastasia collects 8 pebbles of the third type.
  • In the second day she collects 8 pebbles of the fourth type.
  • In the third day she collects 3 pebbles of the first type and1 pebble of the fourth type.
  • In the fourth day she collects 7 pebbles of the fifth type.
  • In the fifth day she collects 1 pebble of the second type. 


题目大意:

沙滩上有n种不同重量的石头,一个人只有两个最大容纳量为m的口袋,而且同一个口袋不能同时装不同种类的石头,给出每种石头的数量,问总共要运多少次才能把所有的石头都运走。


题目分析:

我们知道口袋的容纳量,而且同一个口袋不能同时装两种石头,所以当容纳量为m时,每一种石块的质量为mk,mk+1,mk+2,...,mk+m-1都是等价的,他都要占据m+1次口袋。所以我们只要每次拿一个石子就计算一下他需要用一个口袋运几次,把最终的结果+1再mod 2就可以得到运输的次数


代码样例:

#include<stdio.h>
int main()
{
	int n,i,k,t,key;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		t=0;
		for(i=0;i<n;i++)
		{
			scanf("%d",&key);
			t+=(key+k-1)/k;//计算出重量为key的石子用一个口袋运输需要的次数
		}
		printf("%d\n",(t+1)/2);//如果是偶数,t+1/2==t/2,如果是奇数,t+1/2=t/2+1
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值