A10944 | Anastasia and pebbles
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains two integers $n$ and $k$ ( $1<=n<=10^{5}$ , $1<=k<=10^{9}$ ) — 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}<=10^{4}$ ) — number of pebbles of each type.
The second line contains $n$ integers $w_{1},w_{2},...,w_{n}$ ( $1<=w_{i}<=10^{4}$ ) — number of pebbles of each type.
输出格式
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted