#P6473. Sisyphus and the Mountain of Delay
Sisyphus and the Mountain of Delay
Sisyphus and the Mountain of Delay
Sisyphus is punished by Zeus for offending the gods. Zeus orders Sisyphus to push a giant boulder up a mountain with a slope of length \(L\). Sisyphus pushes at a constant speed \(v\) (i.e. he covers a distance of \(\frac{v}{2}\) in \(\frac{1}{2}\) year). However, Zeus does not want him to reach the peak too quickly.
Zeus can cast \(n\) spells. If he casts the \(i\)-th spell at position \(a_i\) (\(1 \le i \le n\)), then when Sisyphus reaches position \(a_i\) for the first time, he and the boulder immediately roll back to the bottom (the rolling time is negligible). On subsequent passes the spell does not trigger.
For example, suppose Zeus casts spells at \(a_1=3\) and \(a_2=5\) with \(v=1\) and \(L=6\). The process is as follows:
- On the first attempt, Sisyphus reaches \(3\) in 3 years and is reset to the bottom.
- On the second attempt, he reaches \(3\) in 3 years (no reset, as the spell has already been triggered), then reaches \(5\) in 2 additional years and is reset.
- Finally, he climbs from the bottom to the peak in 6 years.
Total time \(T = 3 + 5 + 6 = 14\) years.
If Zeus casts \(m\) spells (with positions sorted in increasing order as \(x_1, x_2, \dots, x_m\)), the total time taken is given by:
\[ T = \frac{x_1 + x_2 + \cdots + x_m + L}{v}. \]Now, Zeus has \(q\) queries. For the \(i\)-th query with a time threshold \(t_i\), determine the minimum number of spells Zeus must cast such that \(T > t_i\). If even casting all available spells does not make \(T > t_i\), output -1.
inputFormat
The first line contains four integers \(L\), \(v\), \(n\), and \(q\), where:
- \(L\) is the length of the mountain,
- \(v\) is Sisyphus's constant speed,
- \(n\) is the number of available spells,
- \(q\) is the number of queries.
The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\) representing the positions at which the spells can be cast.
The third line contains \(q\) space-separated integers \(t_1, t_2, \dots, t_q\) representing the time thresholds.
outputFormat
For each query, output a single integer on a new line: the minimum number of spells required so that the total time \(T = \frac{(\text{sum of selected }a_i) + L}{v}\) is greater than \(t_i\). If it is impossible to exceed \(t_i\) even after using all spells, output -1.
sample
6 1 2 3
3 5
14 13 6
-1
2
1
</p>