CF278A.Circle Line

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The circle line of the Berland subway has nn stations. We know the distances between all pairs of neighboring stations:

  • d1d_{1} is the distance between the 11 -st and the 22 -nd station;
  • d2d_{2} is the distance between the 22 -nd and the 33 -rd station;...
  • dn1d_{n-1} is the distance between the n1n-1 -th and the nn -th station;
  • dnd_{n} is the distance between the nn -th and the 11 -st station.

The trains go along the circle line in both directions. Find the shortest distance between stations with numbers ss and tt .

输入格式

The first line contains integer nn ( 3<=n<=1003<=n<=100 ) — the number of stations on the circle line. The second line contains nn integers d1,d2,...,dnd_{1},d_{2},...,d_{n} ( 1<=di<=1001<=d_{i}<=100 ) — the distances between pairs of neighboring stations. The third line contains two integers ss and tt ( 1<=s,t<=n1<=s,t<=n ) — 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 number ss and tt .

输入输出样例

  • 输入#1

    4
    2 3 4 9
    1 3
    

    输出#1

    5
    
  • 输入#2

    4
    5 8 2 100
    4 1
    

    输出#2

    15
    
  • 输入#3

    3
    1 1 1
    3 1
    

    输出#3

    1
    
  • 输入#4

    3
    31 41 59
    1 1
    

    输出#4

    0
    

说明/提示

In the first sample the length of path 1231→2→3 equals 5, the length of path 1431→4→3 equals 13.

In the second sample the length of path 414→1 is 100, the length of path 43214→3→2→1 is 15.

In the third sample the length of path 313→1 is 1, the length of path 3213→2→1 is 2.

In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.

首页