#P7590. 回旋加速器(2021 CoE-II C)
回旋加速器(2021 CoE-II C)
Description
A cyclotron () is a device that uses magnetic and electric fields to make charged particles move in circular paths and be repeatedly accelerated by a high-frequency electric field. It is an important instrument in high-energy physics.
We study a simplified model of a cyclotron. Consider the cyclotron as a circular track with accelerating cavities on it, numbered from to in order. A beam of protons is injected from one of the cavities. At the moment of injection, the beam’s kinetic energy is zero. The -th cavity can provide the beam with kinetic energy. When the beam travels from cavity to cavity , it loses kinetic energy (since the track is circular, cavity is followed by cavity ).
Given the kinetic energy provided by each cavity and the kinetic energy lost when traveling between cavities, determine whether the beam can complete one full lap around the circular track. If it can, which cavity should be chosen for injection. While traveling between two cavities, the kinetic energy must not be zero. However, when the beam has just arrived at a cavity, its kinetic energy may be zero, because it can immediately obtain the kinetic energy provided by that cavity.
Input Format
The input contains multiple test cases.
The first line contains an integer , the number of test cases. Then there is a blank line.
Next come test cases. Each test case consists of three lines. There is a blank line between two test cases.
The first line of each test case contains an integer , the number of cavities. The second line contains integers, where the -th integer is the kinetic energy that cavity can provide. The third line contains integers, where the -th integer is the kinetic energy loss when the beam travels from cavity to cavity . Since the track is circular, the -th integer on the third line represents the kinetic energy loss when traveling from cavity to cavity .
Output Format
For each test case, output one line. If the beam cannot complete one full lap around the cyclotron, output Failed!. Otherwise, output the index of the cavity where the beam should be injected. If multiple cavities are possible, choose the one with the smallest index.
1
3
1 2 3
2 3 4
Failed!
1
10
1 2 3 4 5 6 7 8 9 10
3 2 1 2 3 4 5 6 7 8
2
Hint
Sample explanation.
Input #1.
This input has cavities, which can provide kinetic energies , , and in order. The loss from cavity to cavity is , from cavity to cavity is , and from cavity to cavity is . No matter which cavity the beam is injected from, the kinetic energy becomes zero while traveling between two cavities, so it cannot complete one full lap.
Input #2.
This input has cavities. If the beam is injected from cavity , it gains kinetic energy , but it loses while traveling from cavity to cavity , so it cannot complete one full lap. If it is injected from any cavity from to , the kinetic energy can be kept non-zero while traveling between cavities, so any of them can be the injection cavity. However, cavity has the smallest index. Note that if the beam is injected from cavity , when it reaches cavity , its kinetic energy is exactly zero. According to the statement, this situation is allowed.
Constraints
- Subtask : , points.
- Subtask : , points.
- Subtask : , points.
- Subtask : , points.
For of the data, , , .
Convention.
The direction of travel of the proton beam is defined as: from cavity to cavity , from cavity to cavity , from cavity to cavity .
Translated by ChatGPT 5
京公网安备 11011102002149号