A8935 | Circle Line
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
- $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$ .
输入格式
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.
The numbers in the lines are separated by single spaces.
输出格式
Print a single number — the length of the shortest path between stations number $s$ and $t$ .
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted