forked from ncduy0303/Competitive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpDiv2d_796.cpp
More file actions
88 lines (69 loc) · 1.56 KB
/
cpDiv2d_796.cpp
File metadata and controls
88 lines (69 loc) · 1.56 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
int solve(ll int x,ll int a[], ll int b)
{
ll int max =0;
ll int temp=0;
ll int cnt=0;
ll int anss=0;
if(x < b){
for (int i =0; i<b; i++ )
{
if(cnt < x)
{
max+= a[i];
temp += a[i];
cnt++;
}
else
{
if(temp + a[i] - a[i-x]> max)
{
max = temp + a[i] - a[i-x];
temp = temp + a[i] - a[i-x];
}
else{
temp = temp + a[i] - a[i-x];
}
}
}
anss = max + x*(x-1)/2;
cout << anss << endl;
}
else{
anss = b*(x-b) + b*(b-1)/2 ;
for(int k=0; k < b ; k++){
anss += a[k];
}
cout << anss << endl;
}
return anss;
}
int main() {
int tc ;
int alpha;
cin >> tc;
for (int t = 1; t <= tc; t++) {
ll int numL;
ll int subL;
ll int ans;
cin >> numL;
cin >> subL;
ll int storeMush[numL];
for(int i = 0; i < numL; i++)
{
cin >>storeMush[i];
}
ans = solve(subL, storeMush, numL);
// cout << "Case #" << t << ": ";
}
}