This page is still under construction.

Parts of this page are still being built. What you see may change.

Dock to the Future

Time limit8sMemory limit512 MB

Summary
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 xx[m] and the speed toward the dock be vv[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 nn modes. When the spaceship is in mode ii (0≤i<n0 \le i < n), the deceleration rate is aia_i[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 xx and vv, your program has to make a deceleration plan. The purpose and priority of your program is as follows:

  1. Stop the spaceship exactly at the limit line. If this is possible, print "perfect".
  2. If it is impossible, stop the spaceship at the position nearest to the limit line but before the line. In this case, print "good dd", where dd is the distance between the limit line and the stopped position. Print three digits after the decimal point.
  3. If that is impossible too, decelerate the spaceship until it has negative speed, and print "try again".
  4. 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 cc, the number of test cases.

Each test case begins with a single integer nn (1≤n≤101 \le n \le 10), the number of deceleration modes. The next line contains nn positive integers a0,…,an−1a_0, \dots, a_{n-1} (1≤ai≤1001 \le a_i \le 100), each giving the deceleration rate of one mode.

The next line contains a single integer qq (1≤q≤201 \le q \le 20), followed by qq lines. Each of them contains two positive integers xx and vv (1≤x,v≤1001 \le x, v \le 100) as defined in the problem statement.

Output

For each pair of xx and vv, print the result on one line. Insert one blank line between test cases.

Examples1

  1. Example 1

    Input
    1
    3
    2 4 6
    4
    10 100
    2 3
    10 6
    7 6
    
    Expected output
    crash
    try again
    good 1.000
    perfect