Dock to the Future
Time limit8sMemory limit512 MB
Given initial distance and speed and a set of deceleration rates, decide each second whether to switch modes so the ship stops at, before, or past the line, or reaches negative speed.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Simulation, Math, Greedy
- Solved
- No attempts yet
Problem
You had long wanted a spaceship, and yesterday you finally bought a used one! You have heard that the hardest part of flying a spaceship is stopping it at the right position in the dock. Of course you are no exception. After a dozen failures, you gave up doing the entire docking process manually. You started writing a simple program that helps you stop a spaceship.
First, you somehow place the spaceship on the straight course toward the dock by hand. Let the distance to the limit line be [m] and the speed toward the dock be [m/s]. Now you turn on the decelerating rocket. Your program will then control the rocket to stop the spaceship at the best position.
Your spaceship has a decelerating rocket with modes. When the spaceship is in mode (), the deceleration rate is [m/s²]. You cannot re-accelerate the spaceship. The accelerating rocket is too powerful to use during docking. You also cannot turn the decelerating rocket off and on again, because your spaceship is used and old, and once you stop the rocket, it is uncertain whether you can turn it on again. In other words, the moment you turn off the rocket is the moment you stop the spaceship at the right position.
After the decelerating rocket is turned on, your program can change the mode or stop the rocket every second, starting at the very moment the deceleration began. Given and , your program has to make a deceleration plan. The purpose and priority of your program is as follows:
- Stop the spaceship exactly at the limit line. If this is possible, print "perfect".
- If it is impossible, stop the spaceship at the position nearest to the limit line but before the line. In this case, print "good ", where is the distance between the limit line and the stopped position. Print three digits after the decimal point.
- If that is impossible too, decelerate the spaceship until it has negative speed, and print "try again".
- If all three of these cases are impossible, the spaceship cannot avoid overrunning the limit line. In this case, print "crash".
Input
The first line of the input contains a single integer , the number of test cases.
Each test case begins with a single integer (), the number of deceleration modes. The next line contains positive integers (), each giving the deceleration rate of one mode.
The next line contains a single integer (), followed by lines. Each of them contains two positive integers and () as defined in the problem statement.
Output
For each pair of and , print the result on one line. Insert one blank line between test cases.