#P2968. [USACO09DEC] Bobsledding S
[USACO09DEC] Bobsledding S
Description
Bessie has entered a bobsled competition because she hopes her hefty weight will give her an advantage over the meter course ().
Bessie pushes off the starting line at meter per second, and her speed can change while she travels along the course. Near the middle of every meter Bessie covers, she can change her speed by using gravity to accelerate by meter per second, or by braking to keep the same speed or decrease her speed by meter per second.
On the way down the hill, Bessie must negotiate turns (). Turn is located meters from the start (), and she must enter the meter that contains turn at a speed of at most meters per second (). Bessie may cross the finish line at any speed.
Help Bessie determine the maximum speed she can attain anywhere on the course without exceeding the speed limits at the turns.
Consider this course with the meter markers as integers and the turn speed limits in brackets (for example, "[3]"):
| 1 2 3 4 5 6 7[3]
|---+---+---+---+---+---+---+
| \
Start + 8
\
+ 9
\
+ 10 +++ 14 (finish)
\ /
11[1] +---+---+
12 13[8]
Below is a chart of Bessie's speeds at the beginning of each meter along the course:
Max: 3 1 8
Mtrs: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Spd: 1 2 3 4 5 5 4 3 4 3 2 1 2 3 4
Her maximum speed was near the beginning of meter .
Input Format
- Line : Two space-separated integers: and .
- Lines to : Line describes turn with two space-separated integers: and .
Output Format
- Line 1: A single integer, representing the maximum speed that Bessie can attain between the start and the finish line, inclusive.
14 3
7 3
11 1
13 8
5
京公网安备 11011102002149号