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:

  1. 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.
  2. 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

 

Input
5 6 3
5 4 3 2 1
Output
5
Input
5 6 3
5 5 5 5 5
Output
10
Input
5 6 3
1 2 1 1 1
Output
2

Sample Output

 

Hint

Consider the first sample.

  1. First Vanya puts the piece of potato of height 5 into processor. At the end of the second there is only amount of height 2 remaining inside.
  2. Now Vanya puts the piece of potato of height 4. At the end of the second there is amount of height 3 remaining.
  3. Vanya puts the piece of height 3 inside and again there are only 3 centimeters remaining at the end of this second.
  4. Vanya finally puts the pieces of height 2 and 1 inside. At the end of the second the height of potato in the processor is equal to 3.
  5. During this second processor finally smashes all the remaining potato and the process finishes.

In the second sample, Vanya puts the piece of height 5 inside and waits for 2 seconds while it is completely smashed. Then he repeats the same process for 4 other pieces. The total time is equal to 2·5 = 10 seconds.

In the third sample, Vanya simply puts all the potato inside the processor and waits 2 seconds.

/*
切土豆机,每秒切k,最多能盛h
都是泪,连for循环里的i都得用long long
*/
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#define INF 0x3f3f3f3f
#define N 100010
using namespace std;
/*bool comp(long long a,long long b)
{
return a>b;
}*/
int main()
{
//freopen("in.txt","r",stdin);
long long n,h,k,cur[N];
scanf("%lld%lld%lld",&n,&h,&k);
//cout<<n<<" "<<h<<" "<<k<<endl;
bool flag=false;
for(long long i=;i<n;i++)
{
scanf("%lld",&cur[i]);
if(cur[i]>)
flag=true;
}
if(!flag)
{
printf("0\n");
return ;
}
long long cut=;
long long sum=;//表示当前机器中有多少土豆
//sort(cur,cur+n);
//for(long long i=0;i<n;i++)
// cout<<cur[i]<<" ";
//cout<<endl;
for(long long i=;i<n;i++)
{
if(sum+cur[i]>h)
{
sum=cur[i];
cut++;
}
else
sum+=cur[i];
cut+=sum/k;
sum%=k;//每一秒都少了k;
}
//cout<<"sum="<<sum<<endl;
if(sum>)
cut++;
//cout<<sum<<endl;
printf("%lld\n",cut);
//cout<<endl;S
return ;
}

暑假练习赛 006 A Vanya and Food Processor(模拟)的更多相关文章

  1. 暑假练习赛 006 E Vanya and Label(数学)

    Vanya and LabelCrawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB    ...

  2. codeforces 677B B. Vanya and Food Processor(模拟)

    题目链接: B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes i ...

  3. 暑假练习赛 006 B Bear and Prime 100

    Bear and Prime 100Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB ...

  4. [ An Ac a Day ^_^ ] CodeForces 677B Vanya and Food Processor 模拟

    题意: 你有一个榨汁机 还有n个土豆 榨汁机可以容纳h高的土豆 每秒可以榨k高的东西 问按顺序榨完土豆要多久 思路: 直接模拟 一开始以为是最短时间排了个序 后来发现多余了…… #include< ...

  5. 暑假练习赛 004 E Joint Stacks(优先队列模拟)

    Joint StacksCrawling in process... Crawling failed Time Limit:4000MS     Memory Limit:65536KB     64 ...

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

    B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...

  7. B. Vanya and Food Processor【转】

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

  8. 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 ...

  9. 暑假练习赛 003 F Mishka and trip

    F - Mishka and trip Sample Output   Hint In the first sample test: In Peter's first test, there's on ...

随机推荐

  1. Azure SQL Database (25) Azure SQL Database创建只读用户

    <Windows Azure Platform 系列文章目录> 本文将介绍如何在Azure SQL Database创建只读用户. 请先按照笔者之前的文章:Azure SQL Databa ...

  2. React的组件用法

    React.createClass() 中文翻译 https://discountry.github.io/react/3.4K ( https://doc.react-china.org868 ) ...

  3. 个人从源码理解JIT模式下angular编译AppModule的过程

    承接上文.笔者之前将一个angular项目的启动过程分为了两步: 创建平台得到 PlatformRef ,以及执行平台引用提供的方法编译根模块 AppModule .本文就将着眼于创建好的平台,从an ...

  4. Divide Sum 比赛时竟然想不出。。。。。。。

    Divide Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitSt ...

  5. Python cPickle模块

    新博客地址:http://gorthon.sinaapp.com/ 持久性就是指保持对象,甚至在多次执行同一程序之间也保持对象.通过本文,您会对 Python对象的各种持久性机制(从关系数据库到 Py ...

  6. vue-resource传参数到后端,后端取不到数据的问题

    先上一段代码: this.$http.post('xxx',{Search_Text:this.search_text}).then(function(response){ // 响应成功回调 thi ...

  7. 命令行参数处理-getopt()和getopt_long()

    在实际编程当中,自己编写代码处理命令行参数是比较麻烦且易出错的.一般我们会直接使用getopt()和getopt_long()函数,下文将介绍具体的使用方法. getopt() getopt()用于处 ...

  8. FPGA IN 金融领域

    何为金融: 金融指货币的发行.流通和回笼,贷款的发放和收回,存款的存入和提取,汇兑的往来等经济活动.金融(FIN)就是对现有资源进行重新整合之后,实现价值和利润的等效流通. 金融主要包括银行.证券.基 ...

  9. Java面向对象 集合(下)

      Java面向对象 集合(下) 知识概要:               (1)Map集合的体系结构 (2)Map集合的方法 (3)HashMap TreeMap (4)集合框架中的常用工具类 ( ...

  10. TableView的性能优化

    现在市场上的iOS应用程序界面中使用最多的UI控件是什么? 答案肯定是UITableView,几乎每一款App都有很多的界面是由UITableView实现的,所以为了做出一款优秀的App,让用户有更好 ...