Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding 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. 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?
Input
The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1000000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Output
Print one integer — the number of times Kolya will have to empty the waste section.
input
2 7 10
5 6
output
1
input
1 5 10
7
output
0
input
3 10 10
5 7 7
output
1
input
1 1 1
1
output
0
题目大意及解题思路
大意:
Kolya有n个大小为a1, a2中, ..., an。Kolya会按照a1,a2,a3...an的顺序将它们放入榨汁机,要放入榨汁器,橙子的大小必须不超过b,所以如果Kolya看到一个更大的橙子,他会把它扔掉,然后继续下一个。榨汁机有一个专门的部分来收集废物。如果Kolya挤压总尺寸严格大于d的橙子,它就会溢出。当这种情况发生时,Kolya清空废料部分(即使没有更多的橙子),继续挤压果汁。他要清空垃圾区多少次?输出打印一个整数Kolya必须清空废料部分的次数。
解题思路:
很简单的模拟题,根据题目意思一步步实现即可,每次判断当前橙子是否大于b,不大于就放到榨汁机(sum+=k),每次还需要判断所有榨的橙子总大小sum是否超过d,超过的话将sum清空,清理次数cnt++。还需要注意的是变量类型要用 long long类型,否则会溢出的!!!
AC代码
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
ll n, d, b,sum=0,cnt=0;
cin >> n >> b >> d;
while (n--)
{
ll k;
cin >> k;
if (k <= b)
{
sum += k;
}
if (sum > d)
{
cnt++;
sum = 0;
}
}
cout << cnt;
return 0;
}