Topic:
Give you a sequence, you can let an interval * k, or you can not multiply, let the interval of the sequence and the maximum
Ideas:
Dynamic programming
dp [1] indicates that the current node is before the current node update interval,
dp [2] indicates that the current node is in the update interval,
dp [3] indicates that the current node is after the update interval
1 #include<cstdio> 2 #include<string.h> 3 #include<algorithm> 4 #include<cmath> 5 #include<iostream> 6 #include<vector> 7 #include<queue> 8 #include<set> 9 #include<map> 10 #include<cctype> 11 #define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) 12 #define mem(a,x) memset(a,x,sizeof(a)) 13 #define lson rt<<1,l,mid 14 #define rson rt<<1|1,mid + 1,r 15 #define P pair<int,int> 16 #define ull unsigned long long 17 using namespace std; 18 typedef long long ll; 19 const int maxn = 1e6 + 10; 20 const ll mod = 998244353; 21 const int inf = 0x3f3f3f3f; 22 const long long INF = 0x3f3f3f3f3f3f3f3f; 23 const double eps = 1e-7; 24 inline ll read() 25 { 26 ll X = 0, w = 0; char ch = 0; 27 while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } 28 while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); 29 return w ? -X : X; 30 } 31 ll n, m; 32 ll dp[10]; 33 int main() 34 { 35 n = read(), m = read(); 36 ll ans = 0; 37 for (int i = 1; i <= n; ++i) 38 { 39 ll num = read(); 40 dp[1] = max(0 * 1ll, dp[1] + num); 41 dp[2] = max(dp[1], dp[2] + num * m); 42 dp[3] = max(dp[2], dp[3] + num); 43 ans = max(ans, dp[3]); 44 } 45 cout << ans << endl; 46 return 0; 47 }