其他分享
首页 > 其他分享> > Educational Codeforces Round 88 (Rated for Div. 2) D. Yet Another Yet Another Task

Educational Codeforces Round 88 (Rated for Div. 2) D. Yet Another Yet Another Task

作者:互联网

题目链接:https://codeforces.com/contest/1359/problem/D

题解

枚举所有可能的情况,其中一定有一个是正确答案。

即每次枚举去掉的最大值,取最大连续子序列的和。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n] = {};
    for (int i = 0; i < n; i++) 
        cin >> a[i];
    int ans = 0;
    for (int maxn = 30; maxn >= -30; maxn--) {
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum = max(0, sum) + a[i];
            ans = max(ans, sum - maxn);
        }
    }
    cout << ans << "\n";
}

 

标签:Educational,int,max,sum,++,maxn,Another,ans,Yet
来源: https://www.cnblogs.com/Kanoon/p/12989145.html