Honest Bureaucracy
InterviewTime limit1sMemory limit1024 MB
Split at most K coins so the favorite with the smallest weight gets as many as possible, with strictly larger weights receiving strictly more.
- Level
Medium6 of 10
- Topics
- Binary search, Sorting, Greedy
- Solved
- No attempts yet
Statement
"It's called bureaucracy."
"Bureaucracy?"
"Yes. Every problem is solved by filling in forms, and a special breed of people called officials reviews them."
***
S. Lukyanenko, Nedotyopa
After the law taxing buildings above two floors was drafted, officials of King Markel the Merry had gold coins left in the budget. They decided to divide the money among themselves. Since only honest officials serve the King, they divide it fairly. Official contributed to the bill. If official receives coins and official receives coins, then holds if and only if . In particular, officials with equal contributions must receive equal amounts.
Some officials are the King's favorites. King Markel wants the favorite with the smallest contribution to end up with as much money as possible. The task does not require maximizing the earnings of officials who are not favorites.
Input
The first line contains a positive integer and two non-negative integers and , separated by spaces: the number of officials, the number of favorites, and the number of coins to divide (, ). The second line contains positive integers (), where is the contribution of official . The third line contains distinct positive integers (), the numbers of the favorites.
Output
If a fair division exists, print POSSIBLE on the first line. On the second line, print non-negative integers separated by spaces, where the -th is the number of coins official receives. You do not have to distribute all coins. King Markel only cares that the favorite with the smallest contribution receives as many coins as possible, and other officials may split the rest however they like. Any correct answer is accepted. If a fair division is impossible, print IMPOSSIBLE.
Hint
Some coins may remain undistributed. In the first example, the leftover coins could also go to the second and fifth officials, but since they are not favorites, that is not required. In the second example, a correct division needs at least 4 coins, but only 3 remain.