#P9948. [USACO20JAN] Race B
[USACO20JAN] Race B
Problem Description
Bessie is participating in a () meter running race. She starts the race at a speed of meters per second. During each second, she can choose to increase her speed by meter per second, keep her speed the same, or decrease her speed by meter per second. For example, in the first second, she can increase her speed to meter per second and run meter, or keep her speed at meters per second and run meters. Bessie's speed will never drop below zero.
Bessie always runs toward the finish line, and she wants to finish the race in an integer number of seconds. Also, she does not want to be running too fast at the finish: at the moment when Bessie completes meters, she wants her speed to be at most () meters per second. For () different values of , Bessie wants to know how fast she can finish the race.
Input Format
The first line of input contains two integers and .
Each of the next lines contains one integer .
Output Format
Output lines. Each line contains one integer: the minimum time needed for Bessie to run meters while having a finishing speed less than or equal to .
10 5
1
2
3
4
5
6
5
5
4
4
Hint
Sample Explanation 1
When , one optimal plan is:
- Increase speed to m/s, run meter.
- Increase speed to m/s, run meters, for a total of meters.
- Keep speed at m/s, for a total of meters.
- Keep speed at m/s, for a total of meters.
- Keep speed at m/s, for a total of meters.
- Decrease speed to m/s, for a total of meters.
When , one optimal plan is:
- Increase speed to m/s, run meter.
- Increase speed to m/s, for a total of meters.
- Increase speed to m/s, for a total of meters.
- Keep speed at m/s, for a total of meters.
- Keep speed at m/s, for a total of meters.
Note that when , the following plan is not valid:
- Increase speed to m/s, run meter.
- Increase speed to m/s, for a total of meters.
- Increase speed to m/s, for a total of meters.
- Increase speed to m/s, for a total of meters.
This is because at the moment Bessie completes meters, her speed is m/s.
Translated by ChatGPT 5