Loading...
Loading...
Loading...
A shop sells bundles of consecutive items from a shelf. The prices on the shelf are n positive integers. A bundle costs the product of its prices. Count the bundles whose cost is strictly below k.
Example
Input
4 100 10 5 2 6
Output
8
The 8 cheap bundles are 10, 5, 2, 6, 10 5, 5 2, 2 6 and 5 2 6.
Try the problem first. Open one hint at a time.
For each right end, count how many starts keep the product below k. All starts from left to right work.
Divide the product by the price that leaves when you move left. Add right - left + 1 each step.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor