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

时间:2023-01-16 13:10:41

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 &num;355 &lpar;Div&period; 2&rpar;-B&period; 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 &num;355 &lpar;Div&period; 2&rpar; B&period; Vanya and Food Processor

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

  3. Codeforces Round &num;368 &lpar;Div&period; 2&rpar; A&period; Brain&&num;39&semi;s Photos (水题)

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

  4. Codeforces Round &num;355 &lpar;Div&period; 2&rpar; A&period; Vanya and Fence 水题

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

  5. Codeforces Round &num;373 &lpar;Div&period; 2&rpar; C&period; Efim and Strange Grade 水题

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

  6. Codeforces Round &num;185 &lpar;Div&period; 2&rpar; A&period; Whose sentence is it&quest; 水题

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

  7. Codeforces Round &num;373 &lpar;Div&period; 2&rpar; A&period; Vitya in the Countryside 水题

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

  8. Codeforces Round &num;371 &lpar;Div&period; 2&rpar; A&period; Meeting of Old Friends 水题

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

  9. Codeforces Round &num;355 &lpar;Div&period; 2&rpar; D&period; Vanya and Treasure 分治暴力

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

随机推荐

  1. python之&lpar;re&rpar;正则表达式上

    python正则表达式知识预备 正则表达式使用反斜杠" \ "来代表特殊形式或用作转义字符,这里跟Python的语法冲突,因此,Python用" \\\\ "表 ...

  2. awakeFromNib与viewDidLoad的区别

    当一个nib文件对应两个类,File's Owner的class为XXXViewController,Objects下的View对应的为XXXView时: awakeFromNib:在XXXView. ...

  3. Hello Dojo&excl;&lpar;翻译&rpar;

    http://dojotoolkit.org/documentation/tutorials/1.10/hello_dojo/index.html 欢迎学习DOJO!在本教程中,你将学些到如何加载DO ...

  4. Mysql支持中文全文检索的插件mysqlcft-应用中的问题

    MySQL目前版本的全文检索没有对中文很好的支持,但可以通过安装mysqlcft插件来实现,具体的安装使用方法:http://blog.s135.com/post/356/ mysqlcft的官方网站 ...

  5. html-----007

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Esper学习之五:EPL语法(一)

    上篇说到了Esper的Context,要是不了解的同学请参看<Esper学习之四:Context>,看过的同学如果还是不理解的话可以给我评论,我将会尽可能的解答.之前有些同学问我Conte ...

  7. Gradle之恋-任务1

    任务作为Gradle的核心功能模块,而且Gradle的任务还可以具有自己的属性和方法,大大扩展了Ant任务的功能.由于任务相关内容比较多,分为两篇来探讨,本篇主要涉及到:任务的定义.任务的属性.任务的 ...

  8. inet&lowbar;pton&comma; inet&lowbar;ntop

    Linux下这2个IP地址转换函数,可以在将IP地址在“点分十进制”和“整数”之间转换而且,inet_pton和inet_ntop这2个函数能够处理ipv4和ipv6.算是比较新的函数了. inet_ ...

  9. Springboot配置文件映射

    添加类和配置文件的映射: 1.定义映射类 @Component @PropertySource("classpath:config/XX.properties") public c ...

  10. 欢迎来怼--第二十二次Scrum会议

    欢迎来怼--第二十二次Scrum会议 一.小组信息 队名:欢迎来怼 小组成员 队长:田继平 成员:李圆圆,葛美义,王伟东,姜珊,邵朔,阚博文 小组照片 二.开会信息 时间:2017/11/10 17: ...