送分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;
}
发表回复