-
Notifications
You must be signed in to change notification settings - Fork 0
/
beautifulArray.cpp
66 lines (56 loc) · 1.26 KB
/
beautifulArray.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// https://codeforces.com/contest/1155/problem/D
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define mem(v) memset((v),0,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b) ((a%mod)*(b%mod)+mod)%mod
#define ad(a,b) (a%mod+b%mod+mod)%mod
#define nl endl
#define inf 1e18
#define cases ll t;cin>>t;while(t--)
const ll N=3e5+5;
ll n,x;
ll a[N];
ll dp[N][3][3];
int main()
{
fast
cin>>n>>x;
for(ll i=0;i<n;i++)
{
cin>>a[i];
}
f(i,n+1)f(j,3)f(k,3)
dp[i][j][k]=-inf;
dp[0][0][0]=0;
f(i,n+1)
f(j,3)
f(k,3)
{
if(j<2)
{
dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
}
if(k<2)
{
dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]);
}
if(i<n)
{
dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]+((j==1)?a[i]:0)*((k==1)?x:1));
}
}
cout<<dp[n][2][2];
return 0;
}