题解 | #小美走公路#
小美走公路
https://www.nowcoder.com/practice/23a0696faab049c2b5beb480db684487
#include <iostream>
#define int long long
using namespace std;
int a[200005];
signed main() {
int n, sum = 0;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
a[n + i] = a[i];
}
for(int i = 1; i <= 2 * n; i++){
a[i] += a[i - 1];
}
int x, y;
cin >> x >> y;
if(x > y)swap(x, y);
cout << min(a[y - 1] - a[x - 1], a[x + n - 1] - a[y - 1]);
}
// 64 位输出请用 printf("%lld")
前缀和的运用 + 拆环为链, 长度加倍
注意:1.long long 2.x和y的大小关系
#悬赏#言の随记题解 文章被收录于专栏
喵喵喵喵喵
查看6道真题和解析