CodeForces

来源:互联网 发布:centos 7 unmount 编辑:程序博客网 时间:2024/05/29 01:52

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 most k pebbles in each pocket at the same time. There are n different pebble types in the park, and there are wi pebbles of the i-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 and k (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 and 1 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.

大致题意:有一个人去捡石头,有两个口袋,每个口袋最多只能装k个石头,而且一个口袋中的石头的种类必须相同,总共有n种石头,每个石头有wi个,问你最少需要多少天才能捡完。

思路:枚举每种石头捡完需要的天数相加即可。

代码如下

#include <stdio.h>#include <bits/stdc++.h>using namespace std;int main(){    std::ios::sync_with_stdio(false);    int n,k;    cin>>n>>k;    int sum=0;//需要用的口袋的个数    for(int i=1;i<=n;i++)    {        int x;        cin>>x;        if(x%k==0)        sum+=x/k;        else         sum+=x/k+1;     }     if(sum%2==0)//一天最多用两个口袋     cout<<sum/2;     else      cout<<sum/2+1;    return 0;}
原创粉丝点击