B题解 | #小美的排列询问# 模拟,分别从两个方向算出x到y的距离,取最小值,O(n)。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <vector>
#include <set>
#include <queue>
#include <iostream>
using namespace std;

void my_ans(){
    long long i,n,m=0,c0,c1,t,x=0,y,mod = 100000000,pos,ans=0;
    cin>>n;
    long long a[n+1];
    for(i=1;i<=n;++i) cin>>a[i];
    cin>>x>>y;
    if (x>y) swap(x,y);
    i=x;
    while(i!=y){
        ans+=a[i];++i;
        if (i>n) i=1;
    }
    t=0;i=y;
    while(i!=x){
        t+=a[i];++i;
        if (i>n) i=1;
    }
    cout<<min(ans, t)<<endl;
    return;
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    long long t=1,i,j;
    //scanf("%d",&t);
    //cin>>t;
    while(t>0){
        --t;my_ans();
    }
    return 0;
}
// 64 位输出请用 printf("%lld")