Box Betting
Time limit1sMemory limit256 MB
The driver picks a random contiguous run of boxes, and the program reports how often its item sum lands below L, within L to U, or above U.
- Level
Medium5 of 10
- Topics
- Prefix sum, Binary search
- Solved
- No attempts yet
Problem
A new delivery driver loads items onto a truck and drives off. He has to deliver at least items, and the truck carries at most items. A load larger than items breaks the truck down under the weight, and a load smaller than items fails the assignment.
At the loading dock there is a row of boxes, and each box holds a fixed number of items. The driver is too shy to ask anyone for help, so he picks one starting box completely at random from the row. He then picks one ending box at random among the boxes from the starting box to the end of the row. Every box between the two picked boxes, including both of them, goes onto the truck.
The other employees bet on whether the truck breaks down, the driver takes too few items, or the driver gets lucky and finishes the assignment. Compute the probability of each of the three outcomes. Assume the boxes the driver picks always fit into the truck.
Input
The first line contains the number of test cases . Each test case consists of three lines. The first line contains the number of boxes . The second line contains a string of uppercase letters with no whitespace, giving the number of items in each box in the order the boxes sit on the dock. A is an empty box, B is a box with 1 item, and in the same way Z is a box with 25 items. The third line contains two integers and . is the number of items the driver has to deliver, and is the largest number of items the truck can take without breaking down.
- Each is an uppercase letter from A to Z
- The starting box is picked with uniform probability among the boxes, and the ending box is picked with uniform probability among the boxes from the starting box to the last box.
Output
For each test case, print three numbers on one line, separated by single spaces. The first number is the probability that the driver finishes the assignment, the second is the probability that he takes too few items, and the third is the probability that the truck breaks down. Print all three values rounded to six digits after the decimal point.