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";
}

 

上一篇:D. Yet Another Monster Killing Problem


下一篇:Codeforces 1359D - Yet Another Yet Another Task (最大子段和/枚举)