【CF709A】Juicer

题目

题意翻译

题目描述

zyk办了一个工厂,里面是流水线作业。

已知一条流水线有n个货物要装载,依次过来货物的容量是a1, a2, …, an,如果货物容量超过b,为不合格货物,不装载,丢弃。

装载货物的箱子容量为d,可以一直装载流水线过来的合格货物,直到超过容量d时,做一次特殊的压缩处理,然后封装,之后换新的箱子继续如此安装。

zyk想知道这条流水线总共做了多少次特殊的压缩处理。

样例中有两个不超过7的货物过来,做一次特殊的压缩处理即可。

输入

第一行输入n,b,d

第二行输入n个整数ai

输出

输出做了多少次特殊的压缩处理

样例输入

2 7 10 5 6

样例输出

1

提示

样例输入2:

1 5 10

7

样例输出2:

0

此样例没有合格产品

样例输入3:

3 10 10

5 7 7

样例输出3:

1

5和7特殊压缩一次

样例输入4:

1 1 1

1

样例输出4:

0

容量只有1,没有超过1,不需要特殊压缩

【数据规模和约定】

1<=n<=100000, 1<=b<=d<=1000000, 1<=ai<=1000000

题目描述

Kolya is going to make fresh orange juice. He has n n oranges of sizes a_{1},a_{2},…,a_{n} a
1
​ ,a
2
​ ,…,a
n
​ . Kolya will put them in the juicer in the fixed order, starting with orange of size a_{1} a
1
​ , then orange of size a_{2} a
2
​ and so on. To be put in the juicer the orange must have size not exceeding b b , so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.

The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d d . When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

输入输出格式

输入格式:
The first line of the input contains three integers n n , b b and d d ( 1<=n<=100000 1<=n<=100000 , 1<=b<=d<=1000000 1<=b<=d<=1000000 ) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d d , which determines the condition when the waste section should be emptied.

The second line contains n n integers a_{1},a_{2},…,a_{n} a
1
​ ,a
2
​ ,…,a
n
​ ( 1<=a_{i}<=1000000 1<=a
i
​ <=1000000 ) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

输出格式:
Print one integer — the number of times Kolya will have to empty the waste section.

输入输出样例

输入样例#1: 复制
2 7 10
5 6
输出样例#1: 复制
1
输入样例#2: 复制
1 5 10
7
输出样例#2: 复制
0
输入样例#3: 复制
3 10 10
5 7 7
输出样例#3: 复制
1
输入样例#4: 复制
1 1 1
1
输出样例#4: 复制
0
说明

In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.

In the second sample, the orange won’t fit in the juicer so Kolya will have no juice at all.

思路

按题意直接模拟即可

代码

#include<iostream>
#include<cstdio>
using namespace std;
int n,b,d;
int sum,ans;
int main()
{
    scanf("%d%d%d",&n,&b,&d);
    for(int i=1;i<=n;i++)
	{
        int a;
        scanf("%d",&a);
        if(a>b)continue;
        sum+=a;
        if(sum>d)
		{
            ans++;sum=0;
        }
    }
    cout<<ans;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值