CF278A.Circle Line

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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

  • _d_1 is the distance between the 1-st and the 2-nd station;

  • _d_2 is the distance between the 2-nd and the 3-rd station;

    ...

  • d__n - 1 is the distance between the n - 1-th and the n-th station;

  • d__n is the distance between the n-th and the 1-st station.

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

伯兰地铁的环形线路共有 nn 个车站。已知所有相邻车站之间的距离:

  • d1d_1 表示第 11 个车站与第 22 个车站之间的距离;

  • d2d_2 表示第 22 个车站与第 33 个车站之间的距离;

    ...

  • dn−1d_{n-1} 表示第 n−1n-1 个车站与第 nn 个车站之间的距离;

  • dnd_n 表示第 nn 个车站与第 11 个车站之间的距离。

列车沿环形线路双向运行。求编号为 ss 和 tt 的两个车站之间的最短距离。

输入格式

The first line contains integer n (3 ≤ n ≤ 100) — the number of stations on the circle line. The second line contains n integers _d_1, _d_2, ..., d__n (1 ≤ d__i ≤ 100) — the distances between pairs of neighboring stations. The third line contains two integers s and t (1 ≤ 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.

第一行包含一个整数 nn(3≤n≤1003 \leq n \leq 100)——环形线路中的车站数量。
第二行包含 nn 个整数 d1, d2, …, dnd_1,\,d_2,\,\dots,\,d_n(1≤di≤1001 \leq d_i \leq 100)——相邻车站之间的距离。
第三行包含两个整数 ss 和 tt(1≤s, t≤n1 \leq s,\,t \leq n)——需要计算最短距离的两个车站的编号。这两个编号可能相同。

每行中的数字以单个空格分隔。

输出格式

Print a single number — the length of the shortest path between stations number s and t.

输出一个整数——车站 ss 与车站 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 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.

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

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

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

在第一个样例中,路径 1 → 2 → 31 → 2 → 3 的长度为 5,路径 1 → 4 → 31 → 4 → 3 的长度为 13。

在第二个样例中,路径 4 → 14 → 1 的长度为 100,路径 4 → 3 → 2 → 14 → 3 → 2 → 1 的长度为 15。

在第三个样例中,路径 3 → 13 → 1 的长度为 1,路径 3 → 2 → 13 → 2 → 1 的长度为 2。

在第四个样例中,起点与终点为同一车站,因此最短距离为 0。

输入解题思路,AI测评打分。不知道怎么写?

首页