#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的大小关系