mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-28 18:41:38 +08:00
26 lines
1.3 KiB
HTML
26 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<h1>1046. Shortest Distance (20)</h1>
|
|
<div id="problemContent">
|
|
<p>The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.</p>
|
|
<p><b>
|
|
Input Specification:
|
|
</b></p>
|
|
<p>Each input file contains one test case. For each case, the first line contains an integer N (in [3, 10<sup>5</sup>]), followed by N integer distances D<sub>1</sub> D<sub>2</sub> ... D<sub>N</sub>, where D<sub>i</sub> is the distance between the i-th and the (i+1)-st exits, and D<sub>N</sub> is between the N-th and the 1st exits. All the numbers in a line are separated by a space. The second line gives a positive integer M (<=10<sup>4</sup>), with M lines follow, each contains a pair of exit numbers, provided that the exits are numbered from 1 to N. It is guaranteed that the total round trip distance is no more than 10<sup>7</sup>.</p>
|
|
<p><b>
|
|
Output Specification:
|
|
</b></p>
|
|
<p>For each test case, print your results in M lines, each contains the shortest distance between the corresponding given pair of exits.</p>
|
|
<b>Sample Input:</b><pre>
|
|
5 1 2 4 14 9
|
|
3
|
|
1 3
|
|
2 5
|
|
4 1
|
|
</pre>
|
|
<b>Sample Output:</b><pre>
|
|
3
|
|
10
|
|
7
|
|
</pre>
|
|
</div> |