CF1155D Beaufitul Array

送分DP。

#include <algorithm>
#include <cmath>
#include <iostream>
using int_t = long long int;
using std::cin;
using std::cout;
using std::endl;
const int_t LARGE = 3e5;

int_t dp[LARGE + 1][3];

int_t n, x;

int main() {
    cin >> n >> x;
    int_t result = 0;
    for (int_t i = 1; i <= n; i++) {
        int_t a;
        cin >> a;
        dp[i][0] = a + std::max(dp[i - 1][0], (int_t)0);
        dp[i][1] = a * x + std::max(dp[i - 1][1], std::max(dp[i - 1][0], 0ll));
        dp[i][2] = a + std::max({dp[i - 1][2], dp[i - 1][1], 0ll});
        result = std::max(result, *std::max_element(dp[i], dp[i] + 3));
    }
    cout << std::max(0ll, result) << endl;
    return 0;
}

 

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理