Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- #define endl '\n'
- const int N = 2e5 + 10;
- int n, p;
- ll sum[N], a[N], k, t;
- void solve() {
- cin >> n >> p;
- for (int i = 1; i <= n; i ++) {
- cin >> a[i];
- sum[i] = a[i] + sum[i - 1];
- }
- cin >> k >> t;
- ll ans = 0;
- for (int i = 1; i <= n; i ++) {
- // cout << i << " *************\n";
- if (i <= p) {
- if (p - i + 1 > t) continue;
- if (t - (p - i + 1) + i <= n) {
- int r = t - (p - i + 1) + i;
- ll now;
- if (r <= p) {
- now = sum[p] - sum[i - 1];
- now += k * t * (p - i + 1) - k * (p - i) * (p - i + 1) / 2;
- } else {
- now = sum[r] - sum[i - 1];
- now += k * t * (r - i + 1) - k * (r - i) * (r - i + 1) / 2;
- }
- // cout << "debug1: " << now << endl;
- ans = max(ans, now);
- continue;
- }
- ll now = sum[n] - sum[i - 1];
- now += k * t * (n - i + 1) - k * (n - i) * (n - i + 1) / 2;
- ans = max(ans, now);
- // cout << "1: " << now << endl;
- } else {
- if (i - p + 1 > t) continue;
- if (t - (i - p + 1) < i) {
- int l = i - (t - (i - p + 1));
- ll now;
- if (l >= p) {
- now = sum[i] - sum[p - 1];
- now += k * t * (i - p + 1) - k * (i - p) * (i - p + 1) / 2;
- } else {
- now = sum[i] - sum[l - 1];
- now += k * t * (i - l + 1) - k * (i - l) * (i - l + 1) / 2;
- }
- // cout << "debug2: " << now << endl;
- ans = max(ans, now);
- continue;
- }
- ll now = sum[i] + k * t * i - k * (i - 1) * i / 2;
- ans = max(ans, now);
- // cout << "2: " << now << endl;
- }
- }
- cout << ans << endl;
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int _ = 1;
- cin >> _;
- while (_--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement