提交时间:2023-08-14 11:58:38

运行 ID: 98074

#include <bits/stdc++.h> #define N (int)(2e5+2) #define ll long long using namespace std; int n, k, x, a[N]; ll f[N]; inline int read() { char c; bool flag = false; int ret = 0; for(c=getchar(); c==' '||c=='\n'; c=getchar()); for(; c!=' '&&c!='\n'; c=getchar()) { if(c == '-') flag = true; else ret = (ret<<3)+(ret<<1)+c-'0'; } if(flag == false) return ret; else return (0-ret); } inline ll mx(ll i, ll j) { return (i>j ? i:j); } int main() { // freopen("sequence.in", "r", stdin); // freopen("sequence.out", "w", stdout); n = read(), k = read(), x = read(); for(register int i=1; i<=n; i++) a[i] = read(); for(register int i=1; i<=n; i++) { for(register int j=i; j>=mx(0, k-(n-i)); j--) { if(j != 0) f[j] = mx(mx(f[j]+a[i]-x, f[j]), f[j-1]+a[i]+x); else f[i] = mx(f[j]+a[i]-x, f[j]); } } printf("%lld\n", f[k]); return 0; }