-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp.cpp
54 lines (51 loc) · 1.07 KB
/
p.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
#include<iostream>
using namespace std;
long long r_arr[1000000];
long long arr[1000000];
long long pre_arr[1000000];
int n, k;
long long score = 0;
int s = 0, e = 0, sum = 0;
// int s_max_id = 0
int s_max = 0;
int main(){
cin >> n;
cin >> k;
for (int i = 0; i<n; i++){
cin >> r_arr[i];
}
for (int i = 0; i<n; i++){
if (r_arr[i]-(k/n) < 0){
score += r_arr[i]*(r_arr[i]+1)/2;
arr[i] = 0;
}
else {
score += (k/n)*(r_arr[i] + r_arr[i]-k/n+1)/2;
arr[i] = r_arr[i]-(k/n);
}
}
pre_arr[0] = 0;
// cout << k%n << "a\n";
for (int i = 1; i<=n; i++){
pre_arr[i] = pre_arr[i-1] + arr[i-1];
}
for (int i = 1; i<=n; i++){
s = i - 1;
e = i + k%n - 1;
sum = 0;
if (e > n){
sum += pre_arr[n] - pre_arr[s];
sum += pre_arr[e%n] - pre_arr[0];
}
else{
sum += pre_arr[e] - pre_arr[s];
}
if(sum > s_max){
s_max = sum;
}
}
//cout << score <<endl;
//cout << s_max <<endl;
score += s_max;
cout << score;
}