eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Bowling Ball

Bowling Ball

There are a lot of mountain ranges in the Neverlands. Every mountain range consists of a number of valleys and summits. The slope between two consecutive summit and valley is always either \textbf{1} or \textbf{-1}, and all the summits and the valleys have integer heights. A bowling ball is swinging on a part of a mountain range consisting of \textbf{n} valleys and \textbf{n-1 }summits. The ball is always touching down the surface of the mountain range (it does not jump). Mountains before the first and after the last valleys are too high such that the ball can never exit the mountain range. At time \textbf{t_0} the ball is located in the valley number \textbf{s} moving to the upper-right direction and it has an initial kinetic energy \textbf{K_0}. The following figure shows a mountain range with \textbf{4} valleys and \textbf{3} summits, and the ball located in the \textbf{2}^nd valley (enumerated from left to right). \includegraphics{https://static.e-olymp.com/content/0e/0e6e1fa43d1d2cb0f3381d81f699971cf9799b8d.jpg} By the simple physics we know that at any time \textbf{t} the ball has a gravitational potential energy \textbf{P_t = mgh} and also a kinetic energy \textbf{K_t = (½)mv^2}, where \textbf{m} is the mass of the ball, \textbf{g} is the constant of the Earth gravity (here equals to \textbf{10}), and \textbf{h} and \textbf{v} are the height and the velocity of the ball at time \textbf{t}. By the transformation of energy from potential to kinetic or vice versa, the total energy of the ball \textbf{P_t + K_t} is fixed during its movements, unless it falls into a valley: at the \textbf{i}^th valley (from left), \textbf{c_i} units of the kinetic energy is lost due to friction or it stops if its kinetic energy is below \textbf{c_i} but consider no friction in other locations. Note that the ball loses \textbf{c_s} unit of energy when it leaves the starting valley at time \textbf{t_0}. You can assume the ball diameter is equal to \textbf{0} and its mass is equal to \textbf{1}. Your task is to find the valley or summit at which the ball will stop. \InputFile There are multiple test cases in the input. The first line of each test case contains three space-separated positive integers \textbf{n}, and \textbf{s} and \textbf{K_0} (\textbf{1} ≤ \textbf{n} ≤ \textbf{3000}, \textbf{1} ≤ \textbf{s} ≤ \textbf{n}, \textbf{1} ≤ \textbf{K_0} ≤ \textbf{10^15}). Each of the following \textbf{n} lines contains two integers \textbf{h_\{i \}}and \textbf{c_i}, the height and friction of the \textbf{i}^th valley. The \textbf{j}^th line of the next \textbf{n-1} lines contains \textbf{H_j}, the height of The \textbf{j}^th summit from the left (\textbf{0} ≤ \textbf{h_i}, \textbf{c_i}, \textbf{H_j} ≤ \textbf{10^9}). It is guaranteed that at least one of \textbf{c_i}s is greater than zero. The input terminates with "\textbf{0 0 0 0}" which should not be processed. \OutputFile For each test case, output a line conforming one of the following formats depending on whether the ball stops at either a valley or a summit. \begin{itemize} \item If the ball stops at valley number \textbf{k}, output "\textbf{Valley: k}" (omit the quotes.) \item If the ball stops at Summit number \textbf{k}, output "\textbf{Summit: k}" (omit the quotes.) \end{itemize}
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
4 2 17
1 1
2 1
1 1
1 2
3
3
2
1 1 1000000000000000
1 1
0 0 0 0
Выходные данные #1
Summit: 2
Valley: 1
Источник 38th ACM International Collegiate Programming Contest, 2013–2014 Asia Region, Tehran Site, Sharif University of Technology, 19–20 December 2013