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

Posted kanoon

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 << "
";
}

 

以上是关于Educational Codeforces Round 88 (Rated for Div. 2) D. Yet Another Yet Another Task的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27