#P15887. [ICPC 2026 NAC] Maki Conveyor Belt
[ICPC 2026 NAC] Maki Conveyor Belt
Description
Alice and Bob are eating at a conveyor belt maki restaurant. (Maki is a kind of sushi). Diners in the restaurant sit around a circular conveyor belt with positions numbered from to in clockwise order. Alice sits at position and Bob sits at position .
The restaurant serves different kinds of maki. There are different plates set out on the conveyor belt. The plate consists of pieces of a single kind of maki and each piece costs coins. The same kind of maki may appear on multiple plates, and have different costs on different plates. No more plates will be added beyond what is already on the conveyor belt and no other customers are present at the restaurant (perhaps they picked a poorly rated maki restaurant).
There is at most one plate per position. Every second, the conveyor belt rotates clockwise. Formally, if there is a plate at position , it moves to position ; and all other plates move from position to position . When a plate is in front of a diner, they may immediately grab any number of pieces from it, or choose not to grab any. For example, if there is a plate with pieces of maki in front of Alice, she can choose to only grab . The diners may grab maki from plates in front of them before the belt first rotates.
Alice and Bob want to return home as quickly as possible to watch their favorite sushi documentary. They know the full layout of the restaurant, and each have a desired number of pieces of each maki type they want to eat in order to be satisfied. Help them determine the minimum time (in seconds) they need to spend in the restaurant and the minimum cost (in coins) for them to become satisfied within that time.
:::align{center}

Initial position of Alice, Bob, and the plates in Sample Input 1. :::
Input Format
The first line of input contains five space-separated integers , , , , and , where is the number of conveyor belt positions, is the number of maki types, is the number of plates, and and are Alice's and Bob's positions respectively.
The second line contains space-separated integers , where is the number of pieces of maki of type that Alice wants to eat.
The third line contains space-separated integers , where is the number of pieces of maki of type that Bob wants to eat.
Each of the next lines describe a plate. The line contains four space-separated integers , , , and , where is the starting position of the plate, is the type of maki on the plate, is the number of pieces on the plate, and is the cost per piece. All plates have different starting positions (all are distinct).
Output Format
Print two integers: the minimum time in seconds that Alice and Bob will need to spend in the restaurant and the minimum cost in coins for them to become satisfied within that minimum time.
If it is impossible for both of them to ever be satisfied, print .
10 2 3 5 7
3 1
4 1
5 1 9 2
6 2 5 3
8 1 9 7
9 20
5 1 1 2 3
2
2
5 1 3 3
impossible
京公网安备 11011102002149号