1.题目描述:

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.

2.题意概述:

这个小女孩有n个口袋,每个口袋最大容量是k,小女孩会把每天拾取的鹅卵石放到口袋里面,条件是每个口袋只能放相同种类的鹅卵石。给你每种鹅卵石的个数,问你最少要多少天才能拾取完。

3.解题思路:

最开始想的是模拟,成功地T了一发,仔细一想:对于每个卵石类型,我们可以计算出最少数量的口袋,阿纳斯塔西娅需要收集这种类型的鹅卵石。 很容易注意到这个数字是等于。 所以问题的答案是.。 解决方案的复杂度是O(N)。

4.AC代码:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100100
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;int main()
{
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);long _begin_time = clock();
#endifint n, k;while(~scanf("%d%d", &n, &k)){int cnt = 0;for (int i = 0; i < n; i++){int x;scanf("%d", &x);while (x > 0){x -= k;cnt++;}}int ans = ceil(1.0 * cnt / 2);printf("%d\n", ans);}
#ifndef ONLINE_JUDGElong _end_time = clock();printf("time = %ld ms.", _end_time - _begin_time);
#endifreturn 0;
}

CF - 789A. Anastasia and pebbles - 贪心+模拟相关推荐

  1. 校内hu测(10.6T2,T3)(乱搞+贪心+模拟)

    @liu_runda T2.便(then) [题目描述] 给出一个R*C的棋盘.共有R行C列,R*C个格子.现要在每个格子都填一个非负整数.使得任意一个2*2的正方形区域都满足这样的性质:左上角的数字 ...

  2. 【NOIP2013】积木大赛(差分数组,贪心模拟)

    题目 原题链接 问题描述 分析 直观思路--贪心模拟:每次都处理最长正整数区段. 以[2,3,4,1,2][2,3,4,1,2][2,3,4,1,2]为例: [2,3,4,1,2]⟹[1,2,3,0, ...

  3. cf:D. The Enchanted Forest【贪心 + 模拟 + 构造】

    分析 找规律然后构造才是王道(分类讨论) 如果k小于等于n,说明不会来回走,所以不会影响增量,只需要找到最大的连续k个即可 可用accumulate操作,注意如果initial = 0的话,最后是会有 ...

  4. CodeForces - 1362E Johnny and Grandmaster(贪心+模拟)

    题目链接:点击查看 题目大意:给出一个基数 p ,再给出 n 个指数 k ,换句话说,现在有一个长度为 n 的序列,每个元素都是 p^k[ i ] ,现在需要将这个序列分到两个集合中,使得两个集合元素 ...

  5. HDU - 6746 Civilization(贪心+模拟)

    题目链接:点击查看 题目大意:中文题面 题目分析:一道比赛时写崩了的模拟,赛后参考别人的代码,发现原来这个题目可以写的如此简单 说会题目,n 只有 500 ,可以 n * n 枚举每个位置作为起点,对 ...

  6. CodeForces - 1321C Remove Adjacent(贪心+模拟)

    题目链接:点击查看 题目大意:给出一个长度不超过100且只包含小写字母的字符串,现在规定,如果某个位置 i 的相邻位置存在着当前位置所代表字母的前一个字母,即 i - 1 和 i + 1 中存在着 a ...

  7. CodeForces - 1303D Fill The Bag(贪心+模拟)

    题目链接:点击查看 题目大意:给出一个背包,容量为 k ,再给出 n 个物品,每个物品的大小保证是 2 的幂次,现在可以进行操作,使得一个物品分为大小相等的,且大小等于原物品一半的两个物品,比如一个物 ...

  8. [cf797c]Minimal string(贪心+模拟)

    题意: 给出了字符串s的内容,字符串t,u初始默认为空,允许做两种操作: 1.把s字符串第一个字符转移到t字符串最后 2.把t字符串最后一个字符转移到u字符串最后 最后要求s.t字符串都为空,问u字符 ...

  9. Codeforces Round #656 (Div. 3) F. Removing Leaves 贪心 + 模拟

    传送门 文章目录 题意: 思路: 题意: 思路: 首先有一个贪心策略就是每次都找一个叶子节点最多的点,让后删掉他的kkk个叶子节点,现在我们就来考虑如何模拟这个过程. 我们整一个vector<s ...

最新文章

  1. Perseus-BERT——业内性能极致优化的BERT训练方案
  2. OpenCV:OpenCV中的 parallel_for 和opencv parallel_for_
  3. 推荐一款功能强大的Tomcat 管理监控工具,可替代Tomcat Manager
  4. (王道408考研操作系统)第三章内存管理-第一节7:非连续分配管理方式之基本分段管理方式
  5. 目标检测多模型集成方法总结
  6. mysql中select 的题型_MYSQL经典题型详情解析
  7. 非printf形式的十六进制和二进制打印(雅虎面试题)
  8. 堪称神级的Spring Boot手册,从基础入门到实战进阶
  9. 20151221jquery学习笔记--验证插件
  10. C3P0连接池配置参数讲解
  11. librtmp 源码分析笔记 ReadN
  12. 关于STM32F107RCT6使用8M晶振串口波特率错误的问题
  13. python的常用标准库
  14. 基于JavaWeb的微博系统设计与实现
  15. 2021-02-01 25 个常用 Matplotlib 图的 Python 代码
  16. 转调小程序(练口琴时用的)
  17. android面板驱动的使用方法,Android 专用驱动之Ashmen
  18. 多ubuntu主机远程桌面连接方案
  19. 三个字组成的字:鑫、淼、焱、众 …………
  20. js实现oss批量下载文件_前端实现批量打包下载文件

热门文章

  1. Qt的对话框与窗口--Splash与登录窗口
  2. php阿里百川即时通讯,阿里百川 客户端SDK示例demo 官方文档过时,有修正说明
  3. QQImage ubuntu20.04版本中文输入问题
  4. 代码的维护成本远远大于开发成本
  5. 一个人的旅行(Djikstra)
  6. mysql recyclebin_MySQL防误删插件Recycle-Bin简介
  7. word文件转md文件
  8. 网络传输的异步、同步传输的实现原理
  9. wps自动插入文献_wps引用文献如何标注
  10. ubuntu安装mosquitto