提交时间:2023-08-14 12:18:07
运行 ID: 98102
#include <bits/stdc++.h> using namespace std; int n, k, x; const int MX = 2e5+1; int a[MX]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k >> x; for (int i = 1; i <= n; ++i) cin >> a[i]; if (!k) { printf("0"); return 0; } if (!x) { int mx = a[1], pos = 1, temp; for (int i = 2; i <= n; ++i) { temp = mx; mx = max(mx, a[i]); if (temp != mx) { pos = i; } } int mxs = mx, mxs2 = mx; for (int i = pos + 1; i <= n; ++i) { mxs2 += a[i]; if (mxs < mxs2) { mxs = mxs2; } } int mxs3 = mx; for (int i = pos - 1; i >= 1; --i) { mxs3 += a[i]; if (mxs < mxs3) { mxs = mxs3; } } printf("%d", mxs3); return 0; } else { if (x > 0) { int mx = a[1], pos = 1, temp; bool b[MX]; memset(b, 1, sizeof(b)); for (int j = 1; j <= k; ++j) { for (int i = 2; i <= n; ++i) { temp = mx; mx = max(mx, a[i]); if (temp != mx && b[i]) { pos = i; b[i] = 0; for (int xx = 1; xx <= n; ++xx) { if (xx != pos) { a[xx] -= x; } } } else { mx = temp; } } a[pos] += x; } for (int i = 1; i <= n; ++i) { temp = mx; mx = max(mx, a[i]); if (temp != mx) { pos = i; } } int mxs = mx, mxs2 = mx; for (int i = pos + 1; i <= n; ++i) { mxs2 += a[i]; if (mxs < mxs2) { mxs = mxs2; } } int mxs3 = mx; for (int i = pos - 1; i >= 1; --i) { mxs3 += a[i]; if (mxs < mxs3) { mxs = mxs3; } } printf("%d", mxs); return 0; } else if (x < 0) { int mn = a[1], pos = 1, temp; bool b[MX]; memset(b, 1, sizeof(b)); for (int j = 1; j <= k; ++j) { for (int i = 2; i <= n; ++i) { temp = mn; mn = min(mn, a[i]); if (temp != mn && b[i]) { pos = i; b[i] = 0; for (int xx = 1; xx <= n; ++xx) { if (xx != pos) { a[xx] -= x; } } } else { mn = temp; } } a[pos] += x; } int mx = a[1]; pos = 1; for (int i = 2; i <= n; ++i) { temp = mx; mx = max(mx, a[i]); if (temp != mx) { pos = i; } } int mxs = mx, mxs2 = mx; for (int i = pos + 1; i <= n; ++i) { mxs2 += a[i]; if (mxs < mxs2) { mxs = mxs2; } } int mxs3 = mx; for (int i = pos - 1; i >= 1; --i) { mxs3 += a[i]; if (mxs < mxs3) { mxs = mxs3; } } printf("%d", mxs); return 0; } } return 0; } // 有几个特判能过