Loading...
Loading...
In a college quiz league, a team plays n rounds. Each round gives points, and a penalty is written as a negative number. The league gives a badge for every block of k consecutive rounds whose total is at least t.
Print how many such blocks there are. Blocks may overlap: rounds 1 to k and rounds 2 to k + 1 are different blocks.
Example 1
Input
6 3 10 4 2 5 1 6 3
Output
3
The block totals are 11, 8, 12 and 10. A total of exactly 10 counts, so the answer is 3.
Example 2
Input
3 2 100 10 20 30
Output
0
The totals are 30 and 50. No block reaches 100.
Try the problem first. Open one hint at a time.
Find the total of the first k rounds and check it against t.
For the next block, add the round that joins and subtract the round that leaves, then check again.
"At least t" means total >= t.
t can be 10^14 and a total can be 10^14 too, so read t and keep the total as long.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor