Active Preparation for the Battle
Time limit2sMemory limit1024 MB
Given n people with strength p and alert cost c, for each query x find the minimum total alert cost needed to reach total strength at least x, or -1 if impossible.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Divide and conquer, Greedy
- Solved
- No attempts yet
Problem
Carnage wants to fight Venom, but first he needs to build up his strength. He learned that eating certain people has a positive effect on symbiote abilities, and the stronger and more capable the person, the more useful they are to eat. However, people tend to resist. A person who is quick enough may raise an alarm before they are dealt with, drawing the attention of the police and Detective Patrick Mulligan.
Carnage's strength is currently 1, the police suspect nothing, and their alert level is 0. Carnage can reach people, and the -th person is described by a pair . When Carnage attempts to eat the -th person, one of two things happens:
- If , Carnage is strong enough to deal with the victim silently, and his strength increases by without raising the police alert level.
- Otherwise, the person is still eaten (and increases by ), but the police alert level increases by .
Carnage can hunt only one target at a time, and each person can be eaten at most once. Carnage chooses the order in which he hunts the victims.
Carnage does not know how dangerous Venom is, so he makes assumptions about Venom's strength. The -th assumption is a potential strength for Venom. For each assumption, find the minimum police alert level that can result when Carnage reaches strength , or determine that such strength cannot be reached.
Input
The first line contains two integers and , the number of potential victims and the number of Carnage's assumptions about Venom's strength (; ).
Each of the next lines describes a person. The -th line contains two integers and separated by a space: the strength level of the -th person and the potential increase in police attention when hunting them (; ).
The next line contains integers separated by spaces. describes Carnage's -th assumption about Venom's strength (). Carnage's memory sometimes fails him, so the same value may appear several times in this sequence.
Output
Print numbers separated by spaces. The -th number is the answer for the -th assumption. If it is impossible to gather strength at least , the answer is . Otherwise, the answer is the minimum police alert level after Carnage gathers that strength.