B. Vanya and Food Processor

题目连接:

http://www.codeforces.com/contest/677/problem/B

Description

Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, than during this second processor smashes all the remaining potato.

Vanya has n pieces of potato, the height of the i-th piece is equal to ai. He puts them in the food processor one by one starting from the piece number 1 and finishing with piece number n. Formally, each second the following happens:

If there is at least one piece of potato remaining, Vanya puts them in the processor one by one, until there is not enough space for the next piece.

Processor smashes k centimeters of potato (or just everything that is inside).

Provided the information about the parameter of the food processor and the size of each potato in a row, compute how long will it take for all the potato to become smashed.

Input

The first line of the input contains integers n, h and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ h ≤ 109) — the number of pieces of potato, the height of the food processor and the amount of potato being smashed each second, respectively.

The second line contains n integers ai (1 ≤ ai ≤ h) — the heights of the pieces.

Output

Print a single integer — the number of seconds required to smash all the potatoes following the process described in the problem statement.

Sample Input

5 6 3

5 4 3 2 1

Sample Output

5

Hint

题意

有一个榨汁机,有n个苹果,一个一个的扔进去,然后榨汁机可以一次性榨掉最后的h高,然后这个榨汁机可以每秒钟榨k米,问你最少需要多少时间

题解:

水题,小于h的肯定都一起扔进去,然后剩下的就是能扔就扔

中间过程用数学去计算就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n;
long long h,k,a[maxn]; int main()
{
scanf("%d%lld%lld",&n,&h,&k);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
long long now = 0,ans = 0;
for(int i=1;i<=n;i++)
{
if(now+a[i]<=h)now+=a[i];
else{
now=a[i];
ans++;
}
long long t = now/k;
ans+=t;
now-=t*k;
}
if(now)ans++;
cout<<ans<<endl;
}

Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题的更多相关文章

  1. Codeforces Round #355 (Div. 2)-B. Vanya and Food Processor,纯考思路~~

    B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. Codeforces Round #355 (Div. 2) B. Vanya and Food Processor

    菜菜菜!!!这么撒比的模拟题,听厂长在一边比比比了半天,自己想一想,然后纯模拟一下,中间过程检测一下,妥妥的就可以过. 题意:有N个东西要去搞碎,每个东西有一个高度,然后有一台机器支持里面可以达到的最 ...

  3. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  4. Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题

    A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...

  5. Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题

    C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...

  6. Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题

    A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  7. Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题

    A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...

  8. Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题

    A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...

  9. Codeforces Round #355 (Div. 2) D. Vanya and Treasure 分治暴力

    D. Vanya and Treasure 题目连接: http://www.codeforces.com/contest/677/problem/D Description Vanya is in ...

随机推荐

  1. Python_oldboy_自动化运维之路(四)

    本节内容 集合 字符编码与转码 函数语法及基本特性 函数参数与局部变量 返回值和嵌套函数 递归 匿名函数 高阶函数 1.集合 集合是一个无序的,不重复的数据组合,它的主要作用如下: 去重,把一个列表变 ...

  2. 经典面试题:js继承方式上

    js不是传统的面向对象语言,那么他是怎么实现继承的呢?由于js是基于原型链实现的面向对象,所以js主要通过原型链查找来实现继承,主要有两大类实现方式,分为基于构造函数的继承,以及非构造函数的继承. 由 ...

  3. java基础61 JavaScript循环语句之while、do...while、for及for...in循环(网页知识)

    本文知识点(目录): 1.while循环语句    2.do...while循环语句    3.for循环语句    4.for...in循环语句    5.附录1(with语句)    6.附录2( ...

  4. thinkphp模型创建

  5. SQL存储过程相关信息查看

    --1.查看所有存储过程与函数      exec sp_stored_procedures     或者      select * from dbo.sysobjects where OBJECT ...

  6. 接口测试工具--Poster与Postman的简单实用

    HTTP/SOAP协议接口的功能测试: 1.浏览器URL(GET请求) http://127.0.0.1:8000/login/?username=zhangsan&password=1234 ...

  7. BFS && DFS

    HDOJ 1312 Red and Black http://acm.hdu.edu.cn/showproblem.php?pid=1312 很裸的dfs,在dfs里面写上ans++,能到几个点就调了 ...

  8. 成功实施的APS项目故事分享---如何管理与激励APS项目团队

    故事背景 A企业是易普优APS重要客户之一,是某行业的龙头企业:APS项目历时7个月顺利上线,十个月验收!通过易普优APS的顺利实施,建成了集团的精益计划管控运营平台,树立计划的权威与指挥棒作用,让物 ...

  9. PHP问题解决

    1.PHP在上传文件的时候出现错误Internal Server Error Internal Server ErrorThe server encountered an internal error ...

  10. autoit v3安装