#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pdd; #define INF 0x7f7f7f #define mem(a, b) memset(a , b , sizeof(a)) #define FOR(i, x, n) for(int i = x;i <= n; i++) // const ll mod = 998244353; // const ll P = 1e9 + 7; // const int maxn = 1e5 + 10; // const double eps = 1e-6; ll n, x; const int N = 3e5 + 10; ll f[N][3][3]; ll a[N]; void solve() { cin >> n >> x; for(int i = 1;i <= n; i++) cin >> a[i]; mem(f, -1); f[0][0][0] = 0; for(int i = 0;i <= n; i++) { for(int j = 0;j < 3; j++) { for(int k = 0;k < 3; k++) { if(j >= 1) f[i][j][k] = max(f[i][j][k], f[i][j - 1][k]); if(k >= 1) f[i][j][k] = max(f[i][j][k], f[i][j][k - 1]); if(i >= 1) f[i][j][k] = max(f[i][j][k], f[i - 1][j][k] + (j == 1 ? a[i] : 0) * (k == 1 ? x : 1)); } } } cout << f[n][2][2] << endl; } signed main() { ios_base::sync_with_stdio(false); //cin.tie(nullptr); //cout.tie(nullptr); #ifdef FZT_ACM_LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); signed test_index_for_debug = 1; char acm_local_for_debug = 0; do { if (acm_local_for_debug == '$') exit(0); if (test_index_for_debug > 20) throw runtime_error("Check the stdin!!!"); auto start_clock_for_debug = clock(); solve(); auto end_clock_for_debug = clock(); cout << "Test " << test_index_for_debug << " successful" << endl; cerr << "Test " << test_index_for_debug++ << " Run Time: " << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl; cout << "--------------------------------------------------" << endl; } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug)); #else solve(); #endif return 0; } |
Double click to view unformatted code.