问题1353--Circle Line

1353: Circle Line

时间限制: 1Sec 内存限制:128 MB
提交:99 解决:55
[ 状态] [ 讨论版] [ 提交] [命题人: ]
题目描述
The circle line of the Berland subway hasnstations. We know the distances between all pairs of neighboring stations:
·d1is the distance between the1-st and the2-nd station;
·d2is the distance between the2-nd and the3-rd station;
...
·dn-1is the distance between then-1-th and then-th station;
·dnis the distance between then-th and the1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numberssandt.
输入
The first line contains integern(3n100) — the number of stations on the circle line. The second line containsnintegersd1,d2,...,dn(1di100) — the distances between pairs of neighboring stations. The third line contains two integerssandt(1s,tn) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
输出
Print a single number — the length of the shortest path between stations numbersandt.
样例输入 Copy
4 2 3 4 9 1 3 4 5 8 2 100 4 1 3 1 1 1 3 1 3 31 41 59 1 1
样例输出 Copy
5 15 1 0
提示
In the first sample the length of path123equals 5, the length of path143equals 13.
In the second sample the length of path41is 100, the length of path4321is 15.
In the third sample the length of path31is 1, the length of path321is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
来源/分类