题解 | 小美走公路

小美走公路

https://www.nowcoder.com/practice/23a0696faab049c2b5beb480db684487

#include <iostream>
using namespace std;

const int N = 1e5 + 10;

long long n, a[N];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i ++ ) cin >> a[i], a[i] += a[i - 1];
    int x, y;
    cin >> x >> y;
    long long ans = 0;
    if (x > y) swap(x, y);
    ans = a[y - 1] - a[x - 1];
    ans = min(ans, (long long)a[n] - ans);
    cout << ans << "\n";
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务