AIM Tech Round 3 (Div. 2) A.Juicer
2016-08-25 02:43
337 查看
A. Juicer
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 ≤ 1 000 000) —
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 ≤ 1 000 000) —
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.
Examples
input
output
input
output
input
output
input
output
Note
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.
这题题意理解很关键呀。
题意:你有n个橙子,把它们按顺序放进容量为d的榨汁机,每次最大只能放入大小为b的橙子(严格大于b则舍弃);一旦榨汁机容量严格超过d时,清空里面所有的橙子;求清空次数;
题意理解了好像也没什么会WA的点,主要是清空时sum=0需要注意;
(明明还没有过main test就来写博客的窝XD……)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 ≤ 1 000 000) —
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 ≤ 1 000 000) —
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.
Examples
input
2 7 10 5 6
output
1
input
1 5 10 7
output
0
input
3 10 105 7 7
output
1
input
1 1 11
output
0
Note
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> #include <algorithm> #include <cstring> #include <cmath> using namespace std; int main(){ int n,b,d; int a,sum=0; int cnt=0; scanf("%d %d %d",&n,&b,&d); while(n--){ scanf("%d",&a); if(a<=b){ sum+=a; } if(sum>d){ cnt++; sum=0; } // cout<<sum<<endl; } printf("%d\n",cnt); }
这题题意理解很关键呀。
题意:你有n个橙子,把它们按顺序放进容量为d的榨汁机,每次最大只能放入大小为b的橙子(严格大于b则舍弃);一旦榨汁机容量严格超过d时,清空里面所有的橙子;求清空次数;
题意理解了好像也没什么会WA的点,主要是清空时sum=0需要注意;
(明明还没有过main test就来写博客的窝XD……)
相关文章推荐
- AIM Tech Round 3 (Div. 2) A. Juicer
- Codeforces刷题之路——AIM Tech Round 3 (Div. 2) A. Juicer
- AIM Tech Round (Div. 2)-A. Save Luke(数学题)
- AIM Tech Round 3 (Div. 2) C.Letters Cyclic Shift
- AIM Tech Round 3 (Div. 2) -- D. Recover the String (构造字符串)
- AIM Tech Round 3 (Div. 2) D. Recover the String 构造、贪心、多坑、WA162
- 【Codeforces AIM Tech Round 4 (Div. 2) C】
- AIM Tech Round (Div. 2)-B. Making a String(贪心)
- AIM Tech Round (Div. 2) D. Array GCD(dp)
- AIM Tech Round (Div. 2) C. Graph and String
- codeforces AIM Tech Round 3 (Div. 2)
- AIM Tech Round 3 (Div. 2)D. Recover the String(贪心+字符串)
- AIM Tech Round 3 (Div. 1) C. Centroids(树形dp)
- AIM Tech Round 4 (Div. 2) B. Rectangles
- AIM Tech Round 4 (Div. 2) B, C 题解
- 【AIM Tech Round 4 (Div. 1) B】Interactive LowerBound
- AIM Tech Round 3 (Div. 2) -- D. Recover the String (思路题目--构造字符串)
- AIM Tech Round 3 (Div. 2) E. Connecting Universities 【构造】
- AIM Tech Round 3 (Div. 2)
- AIM Tech Round 4 (Div. 2) C. Sorting by Subsequences