789A Anastasia and pebbles
1 second
256 megabytes
standard input
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.
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.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
3 2
2 3 4
3
5 4
3 1 8 9 7
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.
题意:有两个口袋,每个口袋只能放一种石头,共有 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的更多相关文章
- Codeforces 789A Anastasia and pebbles(数学,思维题)
A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:stan ...
- Codeforces 789A Anastasia and pebbles( 水 )
链接:传送门 题意:这个人每次都去公园捡石子,她有两个口袋,每个口袋最多装 k 个石子,公园有 n 种石子,每种石子 w[i] 个,询问最少几天能将石子全部捡完 思路:排个序,尽量每天都多装,如果 k ...
- codeforces 789 A. Anastasia and pebbles
链接 A. Anastasia and pebbles 题意 这个人有两个口袋,有n种类型的鹅卵石,每种鹅卵石有wi个,每次可以放同一种最多k个,每次不能把不同类型的鹅卵石放进同一个口袋,但是她可以同 ...
- CF789A. Anastasia and pebbles
/* CF789A. Anastasia and pebbles http://codeforces.com/contest/789/problem/A 水题 题意:有两个背包,每次分别可取k个物品, ...
- 【codeforces 789A】Anastasia and pebbles
[题目链接]:http://codeforces.com/contest/789/problem/A [题意] 有n种物品,每种物品有wi个; 你有两个口袋,每个口袋最多装k个物品; 且口袋里面只能装 ...
- 【贪心】Codeforces Round #407 (Div. 2) A. Anastasia and pebbles
贪心地一个一个尽可能往口袋里放,容易发现和顺序无关. #include<cstdio> #include<iostream> using namespace std; type ...
- Codeforces Round #407 (Div. 2)
来自FallDream的博客,未经允许,请勿转载,谢谢. ------------------------------------------------------ A.Anastasia and ...
- Codeforces Round #407 div2 题解【ABCDE】
Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品.现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去. 题解:其 ...
- cf-789A (思维)
A. Anastasia and pebbles time limit per test 1 second memory limit per test 256 megabytes input stan ...
随机推荐
- python import sklearn出错 "ImportError: DLL load failed: 找不到指定的模块。
安装好sklearn模块后,import的时候出现了以下错误: 但是确实已经装好了,百思不得其解,网上查找之后发现,出现错误原因:安装包的来源问题,也可以理解为包版本兼容问题,有的包使用官方出版,有的 ...
- Pandas数据存取
pd.read_excel('foo.xlsx', 'Sheet1', index_col=None, na_values=['NA']) Pandas数据存取 Pandas可以存取多种介质类型数据, ...
- Python中struct.pack()和struct.unpack()
https://blog.csdn.net/tjuyanming/article/details/79700601 https://www.cnblogs.com/yezl/p/5861787.htm ...
- OpenCV之Vec3f
Vec3f表示的是3通道float类型的 Vect,就相当于3通道float类型的图像(这是其中一个具体化),解释可以从源代码中看出来. 下面给出一个具体的例子: Vec3f point = Vec3 ...
- ssh架构之hibernate(五)hql语句狂练
1.练习题 1.查询所有商品的名称[查询特定属性](只有一个参数的话可以使用List<String>接收数据)2.查询所有商品的名称和供应商[查询特定属性](多个参数可以使用List< ...
- Java 动态代理 两种实现方法
AOP的拦截功能是由java中的动态代理来实现的.说白了,就是在目标类的基础上增加切面逻辑,生成增强的目标类(该切面逻辑或者在目标类函数执行之前,或者目标类函数执行之后,或者在目标类函数抛出异常时候执 ...
- 无线渗透wpa加密路由器
破解wpa加密路由器的原理不同于破解wep加密路由器,只能通过暴力破解获取. 但是获取握手keystream的原理差不多 首先杀死可能会和破解冲突的进程 airmon-ng check kill 开启 ...
- Android Studio 中的FindBugs插件使用,轻松帮你发现Bug (转)
在日常开发过程中难免会因为一时疏忽而留下一些Bug,这些Bug就是埋在程序里的定时炸弹,如果不能及时铲除就会导致程序的不稳定,异常或闪退的现象,从而导致用户的体验的下降.那么怎么才能找出这些埋在程序里 ...
- CentOS rpm
rpm命令是RPM软件包的管理工具.rpm原本是Red Hat Linux发行版专门用来管理Linux各项套件的程序,由于它遵循GPL规则且功能强大方便,因而广受欢迎.逐渐受到其他发行版的采用.RPM ...
- HDFS 总结
HDFS是一个分布式文件存储系统 Client 提交读写请求(拆分blocksize) NameNode 全局把控(知道blocksize的地址) dataNode 存储数据(将数据存储进去,且以P ...