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
  1. 5 6 3
    5 4 3 2 1
Output
  1. 5
Input
  1. 5 6 3
    5 5 5 5 5
Output
  1. 10
Input
  1. 5 6 3
    1 2 1 1 1
Output
  1. 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.

  1. /*
  2. 切土豆机,每秒切k,最多能盛h
  3. 都是泪,连for循环里的i都得用long long
  4. */
  5. #include <string.h>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <stdio.h>
  9. #define INF 0x3f3f3f3f
  10. #define N 100010
  11. using namespace std;
  12. /*bool comp(long long a,long long b)
  13. {
  14. return a>b;
  15. }*/
  16. int main()
  17. {
  18. //freopen("in.txt","r",stdin);
  19. long long n,h,k,cur[N];
  20. scanf("%lld%lld%lld",&n,&h,&k);
  21. //cout<<n<<" "<<h<<" "<<k<<endl;
  22. bool flag=false;
  23. for(long long i=;i<n;i++)
  24. {
  25. scanf("%lld",&cur[i]);
  26. if(cur[i]>)
  27. flag=true;
  28. }
  29. if(!flag)
  30. {
  31. printf("0\n");
  32. return ;
  33. }
  34. long long cut=;
  35. long long sum=;//表示当前机器中有多少土豆
  36. //sort(cur,cur+n);
  37. //for(long long i=0;i<n;i++)
  38. // cout<<cur[i]<<" ";
  39. //cout<<endl;
  40. for(long long i=;i<n;i++)
  41. {
  42. if(sum+cur[i]>h)
  43. {
  44. sum=cur[i];
  45. cut++;
  46. }
  47. else
  48. sum+=cur[i];
  49. cut+=sum/k;
  50. sum%=k;//每一秒都少了k;
  51. }
  52. //cout<<"sum="<<sum<<endl;
  53. if(sum>)
  54. cut++;
  55. //cout<<sum<<endl;
  56. printf("%lld\n",cut);
  57. //cout<<endl;S
  58. return ;
  59. }

暑假练习赛 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. 翻译 | 使用A-Frame打造WebVR版《我的世界》

    原文地址:Minecraft in WebVR with HTML Using A-Frame 原文作者:Kevin Ngo 译者:Felix 校对:阿希 我是 Kevin Ngo,一名就职于 Moz ...

  2. C/C++ 进程通讯(命名管道)

    服务端代码: // pipe_server.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> ...

  3. sdk&jdk&jre

    1. jre and jdkJRE(Java Runtime Enviroment)是Java的运行环境.面向Java程序的使用者,而不是开发者.如果你仅下载并安装了JRE,那么你的系统只能运行Jav ...

  4. 6656 Watching the Kangaroo

    6656 Watching the KangarooDay by day number of Kangaroos is decreasing just liketiger, whale or lion ...

  5. 通过JQuery实现Ajax代码

    今天早上遇到了这个问题,结果我写的顺序是惨不忍睹啊,所有现在留个模版以示标准. $(function(){ $.ajax({ url : "Servlet", //传地址 type ...

  6. PHP连接SQL Server数据库

    服务环境:apache2.2 + PHP5.2 + Sql Server 2008 R2 一.所需库和工具1.SQLSRV20.EXE (php5.2版本对应的的Sql Server扩展库)注释:ph ...

  7. mysqldumpslow -- 分析慢查询日志

    格式:mysqldumpslow [选项] 慢查询日志路径 选项: -s   排序方式,可选值有c(记录次数).t(查询时间).l(锁定时间).r(返回记录).a(平均) -t    显示的记录数 - ...

  8. Python自学笔记-递归函数(来自廖雪峰的官网Python3)

    感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看.   递归函数 ...

  9. python爬取煎蛋网图片

    ``` py2版本: #-*- coding:utf-8 -*-#from __future__ import unicode_literimport urllib,urllib2,timeimpor ...

  10. ZOJ-3933-Team Formation【二分图最佳匹配】【KM】

    http://blog.csdn.net/loy_184548/article/details/51154195    一开始对不同组合得不同分数(mm1,mg2,gg3),想用sap来写,但是保证了 ...