A. Anastasia and pebbles
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
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 种石头, 每种分别w[i] 种

解题思路:计算共需要多少口袋装完, (ans + 1)  / 2 即为所求

 #include <iostream>
#define ll long long
using namespace std;
int main()
{
ll n, k;
cin >> n >> k;
int ans = ;
for(int i = ;i <= n; i++)
{
int w;
cin >> w;
ans += w / k;
if(w % k) ans++;
}
cout << (ans + ) / << endl;
}

789A Anastasia and pebbles的更多相关文章

  1. Codeforces 789A Anastasia and pebbles(数学,思维题)

    A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  2. Codeforces 789A Anastasia and pebbles( 水 )

    链接:传送门 题意:这个人每次都去公园捡石子,她有两个口袋,每个口袋最多装 k 个石子,公园有 n 种石子,每种石子 w[i] 个,询问最少几天能将石子全部捡完 思路:排个序,尽量每天都多装,如果 k ...

  3. codeforces 789 A. Anastasia and pebbles

    链接 A. Anastasia and pebbles 题意 这个人有两个口袋,有n种类型的鹅卵石,每种鹅卵石有wi个,每次可以放同一种最多k个,每次不能把不同类型的鹅卵石放进同一个口袋,但是她可以同 ...

  4. CF789A. Anastasia and pebbles

    /* CF789A. Anastasia and pebbles http://codeforces.com/contest/789/problem/A 水题 题意:有两个背包,每次分别可取k个物品, ...

  5. 【codeforces 789A】Anastasia and pebbles

    [题目链接]:http://codeforces.com/contest/789/problem/A [题意] 有n种物品,每种物品有wi个; 你有两个口袋,每个口袋最多装k个物品; 且口袋里面只能装 ...

  6. 【贪心】Codeforces Round #407 (Div. 2) A. Anastasia and pebbles

    贪心地一个一个尽可能往口袋里放,容易发现和顺序无关. #include<cstdio> #include<iostream> using namespace std; type ...

  7. Codeforces Round #407 (Div. 2)

    来自FallDream的博客,未经允许,请勿转载,谢谢. ------------------------------------------------------ A.Anastasia and ...

  8. Codeforces Round #407 div2 题解【ABCDE】

    Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品.现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去. 题解:其 ...

  9. cf-789A (思维)

    A. Anastasia and pebbles time limit per test 1 second memory limit per test 256 megabytes input stan ...

随机推荐

  1. Python 类的魔术方法

    Python中类的魔术方法 在Python中以两个下划线开头的方法,__init__.__str__.__doc__.__new__等,被称为"魔术方法"(Magic method ...

  2. ABAP 编程

    ABAP Programming Language 的内容主要有: 1.数据类型与数据对象 2.内表和内表结构(Internal Table) 3.数据流控制语句 4.模块化(Modularizati ...

  3. openssl 生成证书

    nginx生成证书,一共四步 1) 生成RSA私钥 (会要求输入至少4位密码)# openssl genrsa -des3 -out private.key 2048 # 2) 根据已生成的RSA私钥 ...

  4. idea 这样 会快点

    最近使用IDEA来开发JAVA应用,对IDEA的界面很有爱,但是缺受不了它的运行速度.每次运行都要编译,所以就有了这边文章   总感觉IDEA的编译速度比eclipse慢,eclipse每次保存都自动 ...

  5. 项目IDEA启动配置

    在所有java启动项中加入 -Djute.maxbuffer=2048000 tomcat 在catalina.bat 中第一行加入 set JAVA_OPTS=-Djute.maxbuffer=20 ...

  6. vuex this.$store.state.属性和mapState的属性中的一点点区别

    做泰康公众号的项目时候有一个需求创建公众号的时候后台有一个社区id提供给后台展现人员和部门,在群发消息时候也要给后台一个社区id只不过获取社区的id接口和上一个不是一样的,本来在页面中写了两个sele ...

  7. array_column 低版本兼容

    function i_array_column($input, $columnKey, $indexKey=null){ if(!function_exists('array_column')){ $ ...

  8. mac通过命令行获取证书和配置文件过期时间

      背景:ios打包证书的profile配置文件过期了,导致以前已经打完的测试包不能安装.所以需要加上检测机制,在打包时提示证书是否将要过期,如果要过期了给出提示   方案: 1.查找profile配 ...

  9. ASP.NET 在请求中检测到包含潜在危险的数据,因为它可能包括 HTML 标记或脚本

    <textarea><%=Server.HtmlEncode(strContent)%></textarea> 转载:https://www.cnblogs.com ...

  10. MyEclipse 10 注册码 破解 到期限制

    转载 https://blog.csdn.net/oJinSeNianHua1/article/details/69226524 把破解界面中的ACTIVATION_KEY复制到弹出的窗体“Enter ...