codeforces278A

时间:2023-03-10 02:22:16
codeforces278A

Circle Line

CodeForces - 278A

郑州地铁的圆线有n个车站。 我们知道所有邻近站点之间的距离:

d[1]是第1站和第2站之间的距离;
d[2]是第2站和第3站之间的距离;

d[n - 1]是第n-1和第n个站之间的距离;
d[n]是第n个站和第1个站之间的距离。
列车沿着两个方向的圆线。 找到具有数字s和t的站点之间的最短距离。

Input

第一行包含整数n(3≤n≤100),表示圆线上的站数。 第二行包含n个整数d[1],d[2],…,d[n](1≤d[i]≤100) 表示相邻站对之间的距离。 第三行包含两个整数s和t(1≤s,t≤n) 表示站点数量,您需要在这些站点之间找到最短距离。 这些数字可以相同。

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

Output

打印一个数字 ,站号s和t之间最短路径的长度。

Examples

样例1

Input:
4
2 3 4 9
1 3

Output:
5

样例2

Input:
4
5 8 2 100
4 1

Output:
15

样例3

Input:
3
1 1 1
3 1

Output:
1

样例4

Input:
3
31 41 59
1 1

Output:
0

Note

在第一个样本中,路径1→2→3的长度等于5,路径1→4→3的长度等于13。

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

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

在第四个样本中,站的数量是相同的,因此最短距离等于0。

sol:这个显然是个环,用前缀和预处理两个点之间的一个方向的距离d1,总长-d1就是另一个方向的距离了

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,Qzh[N];
int main()
{
int i,S,T;
R(n);
Qzh[]=; for(i=;i<=n+;i++) Qzh[i]=Qzh[i-]+read();
R(S); R(T);
if(S>T) swap(S,T);
int tmp=Qzh[T]-Qzh[S];
Wl(min(tmp,Qzh[n+]-tmp));
return ;
}