CF789A.Anastasia and pebbles

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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

阿纳斯塔西娅喜欢在中央乌日兰迪亚公园散步。但她对简单的散步失去了兴趣,于是开始收集乌日兰迪亚的鹅卵石。起初,她决定收集公园里能找到的所有鹅卵石。

她只有两个口袋。每个口袋最多可同时装入 kk 颗鹅卵石。公园中共有 nn 种不同的鹅卵石,其中第 ii 种鹅卵石有 wiw_i 颗。阿纳斯塔西娅非常认真负责,因此她绝不会将不同种类的鹅卵石混装在同一口袋中。不过,她可以同时将不同种类的鹅卵石分别装入两个口袋中。遗憾的是,她无法将全部时间都用于收集鹅卵石,因此每天只能前往公园收集一次鹅卵石。

请帮她计算出收集完中央乌日兰迪亚公园中所有鹅卵石所需的最少天数(注意:阿纳斯塔西娅不能将不同种类的鹅卵石放入同一口袋中)。

输入格式

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 _w_1, _w_2, ..., w__n (1 ≤ w__i ≤ 104) — number of pebbles of each type.

第一行包含两个整数 nn 和 kk(1 ≤ n ≤ 1051 \leq n \leq 10^5,1 ≤ k ≤ 1091 \leq k \leq 10^9)—— 分别表示不同鹅卵石类型的数量,以及阿纳斯塔西娅在一个口袋中最多能放置的鹅卵石数量。

第二行包含 nn 个整数 w1, w2, ..., wnw_1,\,w_2,\,...,\,w_n(1 ≤ wi ≤ 1041 \leq w_i \leq 10^4)—— 每种类型鹅卵石的数量。

输出格式

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

输出仅包含一行,其中有一个整数——Anastasia 收集所有鹅卵石所需的最少天数。

输入输出样例

  • 输入#1

    3 2
    2 3 4

    输出#1

    3
  • 输入#2

    5 4
    3 1 8 9 7

    输出#2

    5

说明/提示

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.

在第一个样例中,阿纳斯塔西娅可以在第一天收集所有第一种类型的鹅卵石,第二天收集所有第二种类型的鹅卵石,第三天收集所有第三种类型的鹅卵石。

第二个样例中的最优操作序列如下:

  • 第一天,阿纳斯塔西娅收集 8 颗第三种类型的鹅卵石。
  • 第二天,她收集 8 颗第四种类型的鹅卵石。
  • 第三天,她收集 3 颗第一种类型的鹅卵石和 1 颗第四种类型的鹅卵石。
  • 第四天,她收集 7 颗第五种类型的鹅卵石。
  • 第五天,她收集 1 颗第二种类型的鹅卵石。

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

首页