#P7590. 回旋加速器(2021 CoE-II C)

回旋加速器(2021 CoE-II C)

Description

A cyclotron (Cyclotron\text{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 nn accelerating cavities on it, numbered from 11 to nn 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 ii-th cavity can provide the beam with eie_i kinetic energy. When the beam travels from cavity ii to cavity i+1i + 1, it loses did_i kinetic energy (since the track is circular, cavity nn is followed by cavity 11).

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 TT, the number of test cases. Then there is a blank line.

Next come TT 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 nn, the number of cavities. The second line contains nn integers, where the ii-th integer is the kinetic energy eie_i that cavity ii can provide. The third line contains nn integers, where the ii-th integer is the kinetic energy loss did_i when the beam travels from cavity ii to cavity i+1i + 1. Since the track is circular, the nn-th integer on the third line represents the kinetic energy loss when traveling from cavity nn to cavity 11.

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 33 cavities, which can provide kinetic energies 11, 22, and 33 in order. The loss from cavity 11 to cavity 22 is 22, from cavity 22 to cavity 33 is 33, and from cavity 33 to cavity 11 is 44. 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 1010 cavities. If the beam is injected from cavity 11, it gains kinetic energy 11, but it loses 33 while traveling from cavity 11 to cavity 22, so it cannot complete one full lap. If it is injected from any cavity from 22 to 1010, the kinetic energy can be kept non-zero while traveling between cavities, so any of them can be the injection cavity. However, cavity 22 has the smallest index. Note that if the beam is injected from cavity 22, when it reaches cavity 33, its kinetic energy is exactly zero. According to the statement, this situation is allowed.


Constraints

  • Subtask 11: 2n102 \le n \le 10, 1010 points.
  • Subtask 22: 2n1032 \le n \le 10^3, 3030 points.
  • Subtask 33: 2n1052 \le n \le 10^5, 3030 points.
  • Subtask 44: 2n1062 \le n \le 10^6, 3030 points.

For 100%100\% of the data, 1T201 \le T \le 20, 0<ei1000 \lt e_i \le 100, 0<di1000 \lt d_i \le 100.


Convention.

The direction of travel of the proton beam is defined as: from cavity 11 to cavity 22, from cavity 22 to cavity 33, \cdots from cavity nn to cavity 11.

Translated by ChatGPT 5