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 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;
}
    原文作者:qscqesze
    原文地址: https://www.cnblogs.com/qscqesze/p/5553131.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞