#P9948. [USACO20JAN] Race B

[USACO20JAN] Race B

Problem Description

Bessie is participating in a KK (1K1091\le K\le 10^9) meter running race. She starts the race at a speed of 00 meters per second. During each second, she can choose to increase her speed by 11 meter per second, keep her speed the same, or decrease her speed by 11 meter per second. For example, in the first second, she can increase her speed to 11 meter per second and run 11 meter, or keep her speed at 00 meters per second and run 00 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 KK meters, she wants her speed to be at most XX (1X1051\le X\le 10^5) meters per second. For NN (1N10001\le N\le 1000) different values of XX, Bessie wants to know how fast she can finish the race.

Input Format

The first line of input contains two integers KK and NN.

Each of the next NN lines contains one integer XX.

Output Format

Output NN lines. Each line contains one integer: the minimum time needed for Bessie to run KK meters while having a finishing speed less than or equal to XX.

10 5
1
2
3
4
5
6
5
5
4
4

Hint

Sample Explanation 1

When X=1X=1, one optimal plan is:

  1. Increase speed to 11 m/s, run 11 meter.
  2. Increase speed to 22 m/s, run 22 meters, for a total of 33 meters.
  3. Keep speed at 22 m/s, for a total of 55 meters.
  4. Keep speed at 22 m/s, for a total of 77 meters.
  5. Keep speed at 22 m/s, for a total of 99 meters.
  6. Decrease speed to 11 m/s, for a total of 1010 meters.

When X=3X=3, one optimal plan is:

  1. Increase speed to 11 m/s, run 11 meter.
  2. Increase speed to 22 m/s, for a total of 33 meters.
  3. Increase speed to 33 m/s, for a total of 66 meters.
  4. Keep speed at 33 m/s, for a total of 99 meters.
  5. Keep speed at 33 m/s, for a total of 1212 meters.

Note that when X=3X=3, the following plan is not valid:

  1. Increase speed to 11 m/s, run 11 meter.
  2. Increase speed to 22 m/s, for a total of 33 meters.
  3. Increase speed to 33 m/s, for a total of 66 meters.
  4. Increase speed to 44 m/s, for a total of 1010 meters.

This is because at the moment Bessie completes 1010 meters, her speed is 44 m/s.

Translated by ChatGPT 5