#P11827. Optimal Stepping Practice
Optimal Stepping Practice
Optimal Stepping Practice
Wujiao Sheng is a student at Electric Gate High School who dreams of becoming a professional footballer. Although he would rather practice football every day than attend school, he obediently goes to class so as not to violate Article 3 of Chapter 2 of the National Education Law.
The route from his home to school is a straight line. We represent the road by a number line where his home is at coordinate \(0\) meters and the school is at coordinate \(e\) meters.
Wujiao Sheng has mastered \(k\) distinct stepping techniques. The \(j\)th technique moves him forward exactly \(s_j\) meters. He practices only these techniques on his way to school and never uses any other means of advancing. Moreover, to avoid being late, he never jumps backwards.
Unfortunately, there are \(n\) potholes along the way. The \(i\)th pothole is located at coordinate \(a_i\) meters. If Wujiao Sheng lands exactly on \(a_i\), his foot gets injured and his dream of becoming a footballer will be dashed. Such landings must be avoided.
Your task is to help him find the best stepping plan that satisfies the following conditions:
- Avoid landing on any pothole.
- Finish exactly at \(e\) meters.
- The plan should maximize the number of times the largest-step technique is used.
- If there is more than one plan with the maximum usage of the largest-step technique, then the plan that uses the second largest-step technique the most is chosen.
- If there is still a tie, compare the usage counts of the third largest-step technique, and so on.
If no valid stepping plan exists, output -1
.
Note: The stepping techniques are considered in descending order by their step lengths when applying the lexicographical optimization criteria. The output should be the counts for each stepping technique in the original input order.
inputFormat
The input consists of five parts:
- An integer \(e\) representing the school coordinate in meters.
- An integer \(n\) representing the number of potholes.
- \(n\) space-separated integers \(a_1, a_2, \dots, a_n\) representing the positions of the potholes.
- An integer \(k\) representing the number of stepping techniques.
- \(k\) space-separated integers \(s_1, s_2, \dots, s_k\) representing the exact lengths (in meters) of each stepping technique.
All values are given in one test case.
outputFormat
If there is a valid stepping plan, output \(k\) integers separated by a space. The \(j\)th integer is the number of times the \(j\)th stepping technique (in the original input order) is used in the optimal plan. If no valid plan exists, output -1
.
sample
10
2
3 7
2
2 3
2 2