-
Notifications
You must be signed in to change notification settings - Fork 0
/
B. Array Walk.cpp
59 lines (57 loc) · 1.44 KB
/
B. Array Walk.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <fstream>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include<bits/stdc++.h>
#include <vector>
using namespace std;
/*
4
5 4 0
1 5 4 3 2
5 4 1
1 5 4 3 2
5 4 4
10 20 30 40 50
10 7 3
4 6 8 2 9 9 7 4 10 9
*/
int t;
int n, k, z;
int arr[300001];
int main(){
cin >> t;
for (int b = 0; b < t; b++){
cin >> n >> k >> z;
for (int x = 0; x < n; x++){
cin >> arr[x];
}
int banswer = 0;
int prefsum[n];
prefsum[0] = arr[0];
for (int x = 1; x < n; x++){
prefsum[x] = prefsum[x - 1] + arr[x];
}
for (int l = 0; l <= z; l++){
for(int x = 1; x < n; x++){
int curanswer = prefsum[x];
int usedmoves = x;
int avmoves = k - usedmoves;
if (avmoves - l * 2 >= 0){
curanswer += (arr[x] + arr[x - 1]) * l;
curanswer += prefsum[x + avmoves - l * 2] - prefsum[x];
banswer = max(banswer, curanswer);
}
else{
if (avmoves - l * 2 == -1){
curanswer += (arr[x] + arr[x - 1]) * l;
curanswer -= arr[x];
banswer = max(banswer, curanswer);
}
}
}
}
cout << banswer << "\n";
}
}