提交时间:2023-08-14 12:27:17

运行 ID: 98200

#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 5; #define ll long long int n, k, x; int a[N]; int main() { // freopen("sequence.in", "r", stdin); // freopen("sequence.out", "w", stdout); ios::sync_with_stdio(0); cin>>n>>k>>x; if(x < 0) { x = -x; k = n - k; } ll maxn = 0, tmp = 0; for(int i = 1;i <= n;i ++) { cin>>a[i]; ll now = 0; for(int j = i;j ;j --) { now += a[j]; maxn = max(maxn, now + x * min(i - j + 1, k) - x * max(0, i - j + 1 - k)); } } cout<<maxn<<endl; return 0; }