2019-5-22训练

http://codeforces.com/problemset/problem/1155/D

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<string>
 6 using namespace std;
 7 typedef long long ll;
 8 const int maxn = 500100;
 9 ll dp[maxn][3];
10 ll n, x;
11 ll a[maxn];
12 ll ans;
13 int main()
14 {
15     cin >> n >> x;
16     for (int i = 1; i <= n; i++)
17     {
18         cin >> a[i];
19     }
20     dp[0][0] = 0;//之前不选的最大
21     dp[0][1] = 0;//选这个最大
22     dp[0][2] = 0;//现在以后不选的最大
23     for(int i = 1; i <= n; i++)
24     {
25         dp[i][0] = max(dp[i - 1][0] + a[i], a[i]);
26 
27         dp[i][1] = max(dp[i - 1][1] + a[i] * x, dp[i - 1][0] + a[i] * x);
28         dp[i][1] = max(dp[i][1], a[i] * x);
29 
30         dp[i][2] = max(dp[i - 1][2] + a[i], dp[i - 1][1] + a[i]);
31         dp[i][2] = max(dp[i][2], a[i]);
32 
33         ans = max(ans, dp[i][0]);
34         ans = max(ans, dp[i][1]);
35         ans = max(ans, dp[i][2]);
36     }
37     printf("%lld\n", ans);
38     return 0;
39 }

 

posted @ 2019-05-22 16:18  Fzzf1  阅读(104)  评论(0编辑  收藏  举报