description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem.
Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a row and they are numbered from $1$ to $n$ from left to right. Each ice sphere has a positive integer price. In this version, some prices can be equal.
An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.
You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered.
-----Input-----
The first line contains a single integer $n$ $(1 \le n \le 10^5)$Β β the number of ice spheres in the shop.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^9)$Β β the prices of ice spheres.
-----Output-----
In the first line print the maximum number of ice spheres that Sage can buy.
In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them.
-----Example-----
Input
7
1 3 2 2 4 5 4
Output
3
3 1 4 2 4 2 5
-----Note-----
In the sample it's not possible to place the ice spheres in any order so that Sage would buy $4$ of them. If the spheres are placed in the order $(3, 1, 4, 2, 4, 2, 5)$, then Sage will buy one sphere for $1$ and two spheres for $2$ each.
|
x = int(input())
arr = list(map(int, input().split()))
arr.sort()
temp = []
n = 0
if x % 2 != 0:
mid = x // 2
arr1 = arr[:mid]
arr2 = arr[mid:]
for i in range(mid):
temp.append(arr2[i])
temp.append(arr1[i])
temp.append(arr[-1])
for i in range(1, x, 2):
if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
n += 1
print(n)
print(*temp)
else:
mid = x // 2
arr1 = arr[:mid]
arr2 = arr[mid:]
for i in range(mid):
temp.append(arr2[i])
temp.append(arr1[i])
for i in range(1, x - 1, 2):
if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
n += 1
print(n)
print(*temp)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem.
Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a row and they are numbered from $1$ to $n$ from left to right. Each ice sphere has a positive integer price. In this version, some prices can be equal.
An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.
You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered.
-----Input-----
The first line contains a single integer $n$ $(1 \le n \le 10^5)$Β β the number of ice spheres in the shop.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^9)$Β β the prices of ice spheres.
-----Output-----
In the first line print the maximum number of ice spheres that Sage can buy.
In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them.
-----Example-----
Input
7
1 3 2 2 4 5 4
Output
3
3 1 4 2 4 2 5
-----Note-----
In the sample it's not possible to place the ice spheres in any order so that Sage would buy $4$ of them. If the spheres are placed in the order $(3, 1, 4, 2, 4, 2, 5)$, then Sage will buy one sphere for $1$ and two spheres for $2$ each.
|
n = int(input())
aaa = list(map(int, input().split()))
aaa.sort()
m0 = (n - 1) // 2
m1 = n // 2
ans = 0
order = [0] * n
for i in range(m1, n):
order[2 * (i - m1)] = aaa[i]
for i in range(m1):
order[2 * i + 1] = aaa[i]
if order[2 * i] > order[2 * i + 1]:
ans += 1
if n % 2 == 0 and order[-2] > order[-1]:
ans -= 1
print(ans)
print(*order)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import stdin
input = stdin.readline
n, m = map(int, input().split())
d = [int(x) for x in input().split()] * 2
d.insert(0, 0)
dd = [0, d[1]]
ps = [0, d[1] * (d[1] + 1) // 2]
res = []
for x in d[2:]:
dd.append(dd[-1] + x)
ps.append(ps[-1] + x * (x + 1) // 2)
p, w = 1, 1
for x in range(2 * n + 1):
if m <= dd[x]:
w = x
break
for x in range(w, 2 * n + 1):
while True:
if m <= dd[x] - dd[p - 1] and m > dd[x] - dd[p]:
break
p += 1
now1 = ps[x] - ps[p]
now2 = dd[x] - dd[p]
now3 = m - now2
now4 = d[p]
now5 = d[p] - now3
now1 += d[p] * (d[p] + 1) // 2 - now5 * (now5 + 1) // 2
res.append(now1)
print(max(res))
|
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = list(map(int, input().split()))
d += d[:]
p = [0] * (2 * n)
p[0] = d[0]
for i in range(1, 2 * n):
p[i] = p[i - 1] + d[i]
s = [0] * (2 * n)
s[0] = (1 + d[0]) * d[0] // 2
for i in range(1, 2 * n):
s[i] = s[i - 1] + (1 + d[i]) * d[i] // 2
ans = 0
for i in range(n):
l = i
r = 2 * n
j = i
while l <= r:
m = (l + r) // 2
if p[m] - (p[i - 1] if i > 0 else 0) >= x:
r = m - 1
j = m
else:
l = m + 1
if j == i:
ans = max(ans, (d[i] - x + 1 + d[i]) * x // 2)
else:
k = x - (p[j - 1] - (p[i - 1] if i > 0 else 0))
delta = min(d[j] - k, d[i] - 1)
ans = max(
ans,
(1 + delta + d[i]) * (d[i] - delta) // 2
+ s[j - 1]
- s[i]
+ (1 + k + delta) * (k + delta) // 2,
)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = sys.stdin.readline
flush = sys.stdout.flush
def psum(a, i, j):
if i <= j:
return a[j + 1] - a[i]
else:
return a[-1] - a[i] + a[j + 1]
def start(i, x):
l = 0
r = n - 1
while l < r:
m = l + r >> 1
if psum(S, i, (i + m) % n) >= x:
r = m
else:
l = m + 1
if l == 0:
return x * (x + 1) >> 1
else:
x -= psum(S, i, (i + l - 1) % n)
return (x * (x + 1) >> 1) + psum(SS, i, (i + l - 1) % n)
def end(i, x):
l = 0
r = n - 1
while l < r:
m = l + r >> 1
if psum(S, (i - m) % n, i) >= x:
r = m
else:
l = m + 1
if l == 0:
return x * (2 * d[i] - x + 1) >> 1
else:
x -= psum(S, (i - l + 1) % n, i)
return (x * (2 * d[(i - l) % n] - x + 1) >> 1) + psum(SS, (i - l + 1) % n, i)
n, x = map(int, input().split())
d = list(map(int, input().split()))
S = [0] * (n + 1)
SS = [0] * (n + 1)
for i in range(1, n + 1):
S[i] = S[i - 1] + d[i - 1]
SS[i] = SS[i - 1] + (d[i - 1] * (d[i - 1] + 1) >> 1)
print(max(max(start(i, x) for i in range(n)), max(end(i, x) for i in range(n))))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
(*d,) = map(int, input().split())
d = 2 * d
d.reverse()
j, ans, total_days, hugs = 0, 0, 0, 0
for i in range(n):
while total_days < x:
hugs += d[j] * (d[j] + 1) // 2
total_days += d[j]
j += 1
tri = (total_days - x) * (total_days - x + 1) // 2
ans = max(ans, hugs - tri)
total_days -= d[i]
hugs -= d[i] * (d[i] + 1) // 2
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
N, X = [int(_) for _ in input().split()]
D = [int(_) for _ in input().split()]
days_per_year = sum(D)
year_value = sum([(d * (d + 1) // 2) for d in D])
answer = year_value * (X // days_per_year)
X = X % days_per_year
answer_year = 0
i = N
pm = N - 1
pd = D[N - 1]
c = 0
to_add = None
while i >= 0:
if i < N:
c -= D[i] * (D[i] + 1) // 2
if to_add is None:
to_add = X
else:
to_add = D[i]
while D[pm] - (D[pm] - pd) <= to_add:
to_add -= D[pm] - (D[pm] - pd)
c += pd * (pd + 1) // 2
pm -= 1
if pm < 0:
pm = N - 1
pd = D[pm]
h = pd
pd -= to_add
l = pd
c += h * (h + 1) // 2 - l * (l + 1) // 2
answer_year = max(answer_year, c)
i -= 1
answer += answer_year
print(answer)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE WHILE VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = list(map(int, input().split()))
e = [d[i] for i in range(n)]
f = [d[i] for i in range(n)]
g = [(d[i] * (d[i] + 1) // 2) for i in range(n)]
h = [(d[i] * (d[i] + 1) // 2) for i in range(n)]
a = [d[i] for i in range(n)]
for i in range(1, n):
d[i] += d[i - 1]
for i in range(n - 2, -1, -1):
e[i] += e[i + 1]
for i in range(1, n):
g[i] += g[i - 1]
for i in range(n - 2, -1, -1):
h[i] += h[i + 1]
ans = 0
for i in range(n):
test = x
res = 0
if test > d[i]:
test -= d[i]
start = 0
end = n - 1
while end - start > 1:
t = (end + start) // 2
if test >= e[t]:
end = t
else:
start = t
if test >= e[start]:
val = start
elif test >= e[end]:
val = end
else:
val = n
res += g[i]
if val != n:
res += h[val]
test -= e[val]
res += test * (2 * a[val - 1] - test + 1) // 2
ans = max(ans, res)
else:
start = 0
end = i
while end - start > 1:
t = (end + start) // 2
if test >= d[i] - d[t]:
end = t
else:
start = t
if test >= d[i] - d[start]:
val = start
else:
val = end
res += g[i] - g[val]
test -= d[i] - d[val]
res += test * (2 * a[val] - test + 1) // 2
ans = max(ans, res)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
arr = list(map(int, input().split()))
i = j = su = hu = an = 0
su += arr[j % n]
hu += su * (su + 1) // 2
while i != n:
while su < x:
j += 1
su += arr[j % n]
hu += arr[j % n] * (arr[j % n] + 1) // 2
if arr[i] > su - x:
hu1 = hu
y = su - x
hu1 -= y * (y + 1) // 2
an = max(hu1, an)
su -= arr[i]
hu -= arr[i] * (arr[i] + 1) // 2
i += 1
print(an)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = sys.stdin.readline
a, b = list(map(int, input().split()))
n = list(map(int, input().split()))
n = n + n
best = 0
left = 0
right = 0
total_cost = 0
total_days = 0
for i in range(len(n)):
x = n[i]
total_cost += x * (x + 1) // 2
total_days += x
if total_days > b:
over = total_days - b
over_cost = over * (over + 1) // 2
while over > n[left]:
x = n[left]
reduce = x * (x + 1) // 2
total_cost -= reduce
total_days -= x
left += 1
over = total_days - b
over_cost = over * (over + 1) // 2
if over <= n[left]:
best = max(best, total_cost - over_cost)
print(best)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def task(n, x, d):
size = 1000001
table = [0] * size
suma = 0
for i in range(1, size):
suma += i
table[i] = suma
start_month = n * 2 - 1
current_month = start_month
total = 0
best = 0
days = 0
while current_month >= 0:
days += d[current_month % n]
if days < x:
total += table[d[current_month % n]]
current_month -= 1
else:
total += table[d[current_month % n]] - table[days - x]
best = max(best, total)
total -= table[d[current_month % n]] - table[days - x]
days -= d[current_month % n]
if start_month != current_month:
days -= d[start_month % n]
total -= table[d[start_month % n]]
start_month -= 1
else:
current_month -= 1
start_month -= 1
print(best)
n, x = map(int, input().split())
d = list(map(int, input().split()))
task(n, x, d)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, m = map(int, input().split())
def sol(a):
a += a
b = list(map(lambda x: (1 + x) * x // 2, a))
for i in range(1, len(b)):
b[i] += b[i - 1]
j = n * 2 - 1
i = n * 2
days = 0
hugs = 0
ans = 0
while j >= 0:
while i >= 0 and a[i - 1] + days <= m:
days += a[i - 1]
i -= 1
hugs = b[j]
if i > 0:
hugs -= b[i - 1]
cur = hugs
if days < m and i > 0:
t = m - days
cur = hugs + t * (a[i - 1] - t + 1 + a[i - 1]) // 2
ans = max(ans, cur)
days -= a[j]
j -= 1
return ans
print(sol(list(map(int, input().split()))))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, m = map(int, input().split())
arr = list(map(int, input().split()))
arr = arr * 2
i = j = ans = td = days = 0
while i < n:
while days < m:
days += arr[j]
td += arr[j] * (arr[j] + 1) // 2
j = j + 1
ans = max(ans, td - (days - m) * (days - m + 1) // 2)
days -= arr[i]
td -= arr[i] * (arr[i] + 1) // 2
i = i + 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = list(map(int, input().split()))
d.reverse()
start = 0
have = 0
i = 0
S = 0
ans = 0
while start < n:
i %= n
if d[i] <= x - have:
have += d[i]
S += d[i] * (d[i] + 1) // 2
i += 1
else:
l1 = d[i]
S += (l1 + l1 - (x - have - 1)) * (x - have) // 2
if ans < S:
ans = S
S -= (l1 + l1 - (x - have - 1)) * (x - have) // 2
S -= d[start] * (d[start] + 1) // 2
have -= d[start]
start += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def binary_search(p, lo, hi, val, arr):
while hi - lo > 1:
mid = lo + (hi - lo) // 2
if arr[p] - arr[mid] == x:
break
elif arr[p] - arr[mid] > x:
lo = mid
else:
hi = mid
return lo
n, x = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr = arr * 2
pre = [0] * (2 * n)
for i in range(2 * n):
pre[i] = arr[i] * (arr[i] + 1) // 2
for i in range(1, 2 * n):
arr[i] += arr[i - 1]
pre[i] += pre[i - 1]
ans = 0
for i in range(2 * n - 1, -1, -1):
l = binary_search(i, 0, 2 * n - 1, x, arr)
e = arr[i] - arr[l] - x
total = pre[i] - pre[l]
total -= e * (e + 1) // 2
ans = max(ans, total)
print(ans)
|
FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def seg(l, r):
global pref
if l == 0:
return pref[r]
return pref[r] - pref[l - 1]
def Bin(day, l, r):
global pref
if l == r:
return l
mid = (l + r) // 2
if mid == 0 and pref[mid] >= day:
return mid
elif mid != 0 and pref[mid] >= day and pref[mid - 1] < day:
return mid
elif pref[mid] >= day:
return Bin(day, l, mid - 1)
else:
return Bin(day, mid + 1, r)
n, x = map(int, input().split())
n *= 2
d = list(map(int, input().split())) * 2
pref = [0] * n
pref[0] = d[0]
for i in range(1, n):
pref[i] = pref[i - 1] + d[i]
res = [0] * n
res[0] = d[0] * (d[0] + 1) // 2
for i in range(1, n):
res[i] = res[i - 1] + d[i] * (d[i] + 1) // 2
ans = -1
for i in range(n // 2, n):
ind = Bin(pref[i] - x + 1, 0, i)
s = pref[i] - pref[ind]
y = d[ind] - (x - s) + 1
ans = max(ans, res[i] - res[ind] + (y + d[ind]) * (x - s) // 2)
print(ans)
|
FUNC_DEF IF VAR NUMBER RETURN VAR VAR RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR RETURN VAR IF VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = list(map(int, input().split())) * 2
d.reverse()
ans = 0
nxt = 0
cur = 0
cnt = 0
for i in range(n):
if i > 0:
cnt -= d[i - 1]
cur -= d[i - 1] * (d[i - 1] + 1) >> 1
while cnt + d[nxt] <= x:
cnt += d[nxt]
cur += d[nxt] * (d[nxt] + 1) >> 1
nxt += 1
rem = x - cnt
val = (d[nxt] + d[nxt] - rem + 1) * rem >> 1
ans = max(ans, cur + val)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
lines = sys.stdin.readlines()
n, x = map(int, lines[0].strip().split(" "))
days = list(map(int, lines[1].strip().split(" ")))
def cal(x):
return x * (x + 1) // 2
val = 0
D = x
pt = 0
while D - days[pt] >= 0:
D -= days[pt]
val += cal(days[pt])
pt = (pt + 1) % n
val += cal(D)
endM = pt
endD = D
maxi = val
for i in range(n):
move = days[i]
val -= cal(days[i])
val -= cal(endD)
move += endD
while move - days[endM] >= 0:
val += cal(days[endM])
move -= days[endM]
endM = (endM + 1) % n
val += cal(move)
endD = move
maxi = max(maxi, val)
val = 0
D = x
pt = n - 1
while D - days[pt] >= 0:
D -= days[pt]
val += cal(days[pt])
pt = (pt - 1) % n
val += cal(days[pt]) - cal(days[pt] - D)
endM = pt
endD = D
maxi = max(maxi, val)
for i in range(n - 1, -1, -1):
move = days[i]
val -= cal(days[i])
val -= cal(days[endM]) - cal(days[endM] - endD)
move += endD
while move - days[endM] >= 0:
val += cal(days[endM])
move -= days[endM]
endM = (endM - 1) % n
val += cal(days[endM]) - cal(days[endM] - move)
endD = move
maxi = max(maxi, val)
print(maxi)
|
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = list(map(int, input().split())) * 3
d.reverse
e = [(i * (i + 1) // 2) for i in d]
def f(a, b):
c = a - b
return a * (a + 1) // 2 - c * (c + 1) // 2
ss = 0
ee = 0
whole = d[ee]
tsol = e[ee]
while True:
ee += 1
if whole + d[ee] > x:
ee -= 1
break
whole += d[ee]
tsol += e[ee]
tend = f(d[ee + 1], x - whole)
tsol += tend
sol = tsol
while ss < n:
whole -= d[ss]
tsol -= e[ss] + tend
ss += 1
while True:
ee += 1
if whole + d[ee] > x:
ee -= 1
break
whole += d[ee]
tsol += e[ee]
tend = f(d[ee + 1], x - whole)
tsol += tend
sol = max(tsol, sol)
print(sol)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER EXPR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR WHILE NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER WHILE NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = list(map(int, input().split()))
m, i = 0, 0
m2, i2 = 0, x
s = 0
while i2 > d[m2]:
i2 -= d[m2]
s += d[m2] * (d[m2] + 1) // 2
m2 += 1
s += i2 * (i2 + 1) // 2
res = s
while m < n:
a = min(d[m2] - i2, d[m] - i)
s += a * (i2 - i)
res = max(res, s)
i += a
i2 += a
if i >= d[m]:
i = 0
m += 1
if i2 >= d[m2]:
i2 = 0
m2 = (m2 + 1) % n
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def BS(arr, l, n, tar, mo):
r = n + l - 1
const = arr[l] - mo[l]
while l < r:
mid = l + (r - l) // 2
if arr[mid] - const >= tar:
r = mid
else:
l = mid + 1
return l
n, x = list(map(int, input().split(" ")))
arr = list(map(int, input().split(" ")))
month = arr[:]
month += month
days = [(0) for i in range(2 * n)]
days[0] = month[0]
for i in range(1, 2 * n):
days[i] += days[i - 1] + month[i]
for i in range(n):
arr[i] = arr[i] * (arr[i] + 1) // 2
new = arr + arr
hug = [(0) for i in range(2 * n)]
hug[0] = new[0]
for i in range(1, 2 * n):
hug[i] += hug[i - 1] + new[i]
MAX = 0
for i in range(n):
r = BS(days, i, n, x, month)
tt = hug[r] - hug[i + 1] + new[i + 1]
temp = days[r] - days[i + 1] + month[i + 1]
temp = x - temp
temp = month[i] - temp
tt += new[i] - temp * (temp + 1) // 2
MAX = max(MAX, tt)
print(MAX)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = sys.stdin.readline
n, x = map(int, input().split())
d = list(map(int, input().split()))
mx = 0
i = n - 1
j = n - 1
k = 0
cursum = 0
miss = x
while d[j] < miss:
miss -= d[j]
cursum += d[j] * (d[j] + 1) // 2
j -= 1
k = d[j] - miss
cursum += d[j] * (d[j] + 1) // 2
cursum -= k * (k + 1) // 2
miss = 0
mx = cursum
while i >= 0:
miss = d[i]
cursum -= d[i] * (d[i] + 1) // 2
cursum += k * (k + 1) // 2
cursum -= d[j] * (d[j] + 1) // 2
miss -= k
miss += d[j]
while d[j] < miss:
miss -= d[j]
cursum += d[j] * (d[j] + 1) // 2
j -= 1
if j < 0:
j = n - 1
k = d[j] - miss
cursum += d[j] * (d[j] + 1) // 2
cursum -= k * (k + 1) // 2
miss = 0
mx = max(mx, cursum)
i -= 1
print(mx)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = list(map(int, input().split()))
n *= 2
d += d
def val(m):
return m * (m + 1) // 2
pref = [0] * (n + 1)
for i in range(n):
pref[i + 1] = pref[i] + d[i]
wyn = -65836576238468732467823442342323468236784
indeksy = []
ind = 0
for i in range(1, n // 2 + 1):
while True:
if pref[ind + 1] - pref[i - 1] <= x - 1:
ind += 1
else:
break
if pref[ind] - pref[i - 1] == x - 1:
indeksy.append([i, ind])
pref_hugs = [0] * (n + 1)
for i in range(n):
pref_hugs[i + 1] = pref_hugs[i] + val(d[i])
for indeks in indeksy:
dl = indeks[0]
dp = indeks[1]
if d[dl - 1] > d[dp]:
cyk = pref_hugs[dp + 1] - pref_hugs[dl - 1] - d[dp] * (d[dp] - 1) // 2
else:
cyk = (
pref_hugs[dp] - pref_hugs[dl] + d[dl - 1] + d[dl - 1] * (d[dl - 1] + 1) // 2
)
wyn = max(cyk, wyn)
ind = 0
for i in range(n + 1):
if pref[i] < x:
continue
if pref[i] == x:
wyn = min(wyn, pref_hugs[i])
continue
while pref[i] - pref[ind] > x:
ind += 1
cyk = pref_hugs[i] - pref_hugs[ind]
leftovers = x - (pref[i] - pref[ind])
cyk += (2 * d[ind - 1] - (leftovers - 1)) * leftovers // 2
wyn = max(wyn, cyk)
print(wyn)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def countGreater(arr, n, k):
l = 0
r = n - 1
leftGreater = n
while l <= r:
m = int(l + (r - l) / 2)
if arr[m] >= k:
leftGreater = m
r = m - 1
else:
l = m + 1
return n - leftGreater
n, m = map(int, input().split())
l = list(map(int, input().split()))
l = l + l
pre1 = [0] * (2 * n + 1)
t = 1
pre2 = [0] * (2 * n + 1)
for i in range(2 * n):
pre1[t] = pre1[t - 1] + l[i % n]
pre2[t] = pre2[t - 1] + (l[i % n] * l[i % n] + l[i % n]) // 2
t += 1
tot = 0
for i in range(n):
ans = 0
c = 2 * n + 1 - countGreater(pre1, 2 * n + 1, pre1[i + n + 1] - m)
ans = pre2[i + n + 1] - pre2[c]
left = m - pre1[i + n + 1] + pre1[c]
r = l[c - 1] - left
ans += (l[c - 1] * l[c - 1] + l[c - 1]) // 2 - (r * r + r) // 2
tot = max(tot, ans)
print(tot)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def vacation(n, x, days):
hugs = 0
pref = [0]
for i in range(n):
pref.append(pref[-1] + days[i])
for i in range(n):
pref.append(pref[-1] + days[i])
ds = [(i * (i + 1) // 2) for i in days]
pref_hugs = [0]
for i in range(n):
pref_hugs.append(pref_hugs[-1] + ds[i])
for i in range(n):
pref_hugs.append(pref_hugs[-1] + ds[i])
for i in range(n):
lo = i
hi = 2 * n + 1
while lo < hi:
mid = (lo + hi) // 2
if pref[mid] - pref[i] < x:
lo = mid + 1
else:
hi = mid
lo -= 1
remain = x + pref[i] - pref[lo]
s = pref_hugs[lo] - pref_hugs[i] + remain * (remain + 1) // 2
hugs = max(hugs, s)
for i in range(n + 1, 2 * n + 1):
lo = 0
hi = i
while lo < hi:
mid = (lo + hi) // 2
if pref[i] - pref[mid] <= x:
hi = mid
else:
lo = mid + 1
remain = x + pref[lo] - pref[i]
s = (
pref_hugs[i]
- pref_hugs[lo]
+ (2 * days[(lo - 1) % n] - remain + 1) * remain // 2
)
hugs = max(hugs, s)
return hugs
n, x = map(int, input().split())
days = [int(s) for s in input().split()]
print(vacation(n, x, days))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import stdin, stdout
input = stdin.readline
def binarySearch(daysPrefix, target, low, high):
while low < high:
mid = low + (high - low + 1) // 2
if daysPrefix[mid] == target:
return mid
elif daysPrefix[mid] < target:
low = mid
else:
high = mid - 1
return low
n, x = map(int, input().split())
d = list(map(int, input().split()))
days = d + d
score, day = 0, 0
scorePrefix = []
daysPrefix = []
for value in days:
score += value * (value + 1) // 2
scorePrefix.append(score)
day += value
daysPrefix.append(day)
mx = 0
for index in range(2 * n - 1, n - 1, -1):
search = daysPrefix[index] - x
ind = binarySearch(daysPrefix, search, 0, index - 1)
daysValue = daysPrefix[index] - daysPrefix[ind]
scoreValue = scorePrefix[index] - scorePrefix[ind]
dayDiff = daysValue - x
scoreDiff = dayDiff * (dayDiff + 1) // 2
mx = max(scoreValue - scoreDiff, mx)
print(mx)
|
ASSIGN VAR VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def li():
return [int(i) for i in input().rstrip().split()]
def st():
return str(input().rstrip())[2:-1]
def val():
return int(input().rstrip())
def li2():
return [str(i)[2:-1] for i in input().rstrip().split()]
def li3():
return [int(i) for i in st()]
n, x = li()
l = li()
l = l + l
startindices = [(0) for i in l]
i = j = ans = curr = days = 0
while j < 2 * n:
if days + l[j] <= x:
days += l[j]
curr += l[j] * (l[j] + 1) // 2
else:
while l[j] + days - (l[i] - startindices[i]) > x:
left = startindices[i]
days -= l[i] - left
curr -= l[i] * (l[i] + 1) // 2 - left * (left + 1) // 2
i += 1
deletetill = l[j] + days - x
left = startindices[i]
curr -= (left + deletetill) * (left + deletetill + 1) // 2 - left * (
left + 1
) // 2
startindices[i] += deletetill
days = x
curr += l[j] * (l[j] + 1) // 2
ans = max(ans, curr)
j += 1
print(ans)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER WHILE BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
import time
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
class Bisect:
def __init__(self, func):
self.__func = func
def bisect_left(self, x, lo, hi):
while lo < hi:
mid = (lo + hi) // 2
if self.__func(mid) < x:
lo = mid + 1
else:
hi = mid
return lo
def bisect_right(self, x, lo, hi):
while lo < hi:
mid = (lo + hi) // 2
if x < self.__func(mid):
hi = mid
else:
lo = mid + 1
return lo
def slv(N, X, D):
def f(n):
return (n**2 + n) // 2
yh = sum(map(f, D))
yn = sum(D)
D.reverse()
D += D
sd = [0]
sh = [0]
for d in D:
sd.append(sd[-1] + d)
sh.append(sh[-1] + f(d))
o = X // yn * yh
X %= yn
ans = 0
for i in range(N):
j = Bisect(lambda x: sd[x] - sd[i]).bisect_left(X + 1, i, i + N)
u = sd[j] - sd[i]
r = u - X
t = sh[j - 1] - sh[i] + f(D[j - 1]) - f(r)
ans = max(ans, o + t)
return ans
def main():
N, X = read_int_n()
D = read_int_n()
print(slv(N, X, D))
main()
|
IMPORT IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING RETURN VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = sys.stdin.readline
def sum_upto_n(n):
return n * (n + 1) // 2
def main():
test = 1
for _ in range(test):
n, x = map(int, input().split())
ara = [int(num) for num in input().split()]
ara = ara * 2
days = x
hugs = 0
ans = 0
right = 2 * n - 1
left = 2 * n - 1
while right >= n:
while ara[left] < days:
hugs += sum_upto_n(ara[left])
days -= ara[left]
left -= 1
ans = max(ans, hugs + sum_upto_n(ara[left]) - sum_upto_n(ara[left] - days))
if left != right:
days += ara[right]
hugs -= sum_upto_n(ara[right])
right -= 1
else:
left -= 1
right -= 1
print(ans)
main()
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = sys.stdin.readline
def binary_search():
l, r = i, 2 * n - 1
while l <= r:
m = (l + r) // 2
if acc1[m + 1] - acc1[i] <= x:
l = m + 1
else:
r = m - 1
return r
n, x = map(int, input().split())
d = list(map(int, input().split()))
d.reverse()
d += d
acc1 = [0]
for di in d:
acc1.append(acc1[-1] + di)
acc2 = [0]
for di in d:
acc2.append(acc2[-1] + di * (di + 1) // 2)
ans = 0
for i in range(n):
b = binary_search()
amari = x - (acc1[b + 1] - acc1[i])
top = d[(b + 1) % n]
ans = max(ans, acc2[b + 1] - acc2[i] + amari * (2 * top - amari + 1) // 2)
print(ans)
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import stdin
input = stdin.buffer.readline
def f(a, d, n):
return (2 * a + d * (n - 1)) * n // 2
def bs1(x, ll):
l, r = ll, 2 * n
while l < r:
m = l + r + 1 >> 1
if dd[m] > x:
r = m - 1
else:
l = m
return l
def bs2(x, rr):
l, r = 0, rr
while l < r:
m = l + r >> 1
if dd[m] < x:
l = m + 1
else:
r = m
return l
n, k = map(int, input().split())
ans = 0
(*d,) = map(int, input().split())
d = d + d
pref, dd = [0] * (2 * n + 1), [0] * (2 * n + 1)
for i in range(2 * n):
dd[i] = dd[i - 1] + d[i]
for i in range(2 * n):
pref[i] = pref[i - 1] + f(1, 1, d[i])
for i in range(n):
if k - 1 < d[i]:
ans = max(ans, f(1, 1, k - 1) + d[i - 1])
continue
x = bs1(k - 1 + dd[i] - 1, i)
tmp = pref[x] - pref[i]
ans = max(ans, tmp + f(1, 1, k - 1 - dd[x] + dd[i]) + d[i])
for i in range(n, 2 * n):
if k < d[i]:
ans = max(ans, f(d[i], -1, k))
continue
x = bs2(dd[i] - k + 1, i)
tmp = pref[i] - pref[x]
ans = max(ans, tmp + f(dd[x] - dd[x - 1], -1, k - dd[i] + dd[x]))
print(ans)
|
ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr = arr * 2
i = 0
j = 0
days = 0
res = 0
ans = 0
while i < n:
while days < x:
days += arr[j]
res += arr[j] * (arr[j] + 1) // 2
j += 1
e = days - x
temp = res - e * (e + 1) // 2
ans = max(ans, temp)
days -= arr[i]
res -= arr[i] * (arr[i] + 1) // 2
i += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import gettrace, stdin
if not gettrace():
def input():
return next(stdin)[:-1]
def main():
def solve():
n, k = map(int, input().split())
li = [0] + [int(x) for x in input().split()]
for i in range(n):
li.append(li[i])
pref1 = [0] * (2 * n + 1)
pref2 = [0] * (2 * n + 1)
pref1[1] = li[1] * (li[1] + 1) // 2
pref2[1] = li[1]
for i in range(2, 2 * n + 1):
pref1[i] = pref1[i - 1] + li[i] * (li[i] + 1) // 2
pref2[i] = pref2[i - 1] + li[i]
mx = 0
for i in range(2 * n, n - 1, -1):
ans = i
low, high = 0, i
while low <= high:
mid = (low + high) // 2
if pref2[i] - pref2[mid] < k:
high = mid - 1
ans = mid
else:
low = mid + 1
rem = pref2[i] - pref2[ans - 1] - k
val = pref1[i] - pref1[ans - 1] - rem * (rem + 1) // 2
mx = max(val, mx)
print(mx)
solve()
main()
|
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import gettrace, stdin
if not gettrace():
def input():
return next(stdin)[:-1]
def main():
n, x = map(int, input().split())
dd = [int(a) for a in input().split()]
ddh = []
ddd = [0]
for i in range(n):
ddh.append(dd[i] * (dd[i] + 1) // 2)
for i in range(2 * n):
ddd.append(dd[i % n] + ddd[-1])
best = 0
hugs = 0
l = 1
r = 1
while ddd[r] < x:
hugs += ddh[(r - 1) % n]
r += 1
while r < n * 2:
hugs += ddh[(r - 1) % n]
firstday = ddd[r] - x
while firstday >= ddd[l]:
hugs -= ddh[(l - 1) % n]
l += 1
lostdays = dd[(l - 1) % n] - (ddd[l] - firstday)
h = hugs - lostdays * (lostdays + 1) // 2
best = max(best, h)
r += 1
print(best)
main()
|
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = list(map(int, input().split()))
d.extend(d)
k = c = 0
i = 2 * n - 1
a = x
j = i
if n == 1:
print((2 * d[0] - a + 1) * a // 2)
else:
while i >= n:
while a > 0:
if d[j] < a:
c += d[j] * (d[j] + 1) // 2
a -= d[j]
j -= 1
else:
b = c + (2 * d[j] - a + 1) * a // 2
if b > k:
k = b
if x - a >= d[i]:
a += d[i]
c -= d[i] * (d[i] + 1) // 2
i -= 1
if j > i:
j = i
break
print(k)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR WHILE VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def rs():
return input().strip()
def ri():
return int(input())
def ria():
return list(map(int, input().split()))
def ia_to_s(a):
return " ".join([str(s) for s in a])
def nn2(n):
return n * (n + 1) // 2
def solve(n, x, d):
d = d + d
ans = 0
i = 0
j = 0
days = 0
cnt = 0
while i < 2 * n:
while j < 2 * n and days < x:
days += d[j]
cnt += nn2(d[j])
j += 1
ans = max(ans, cnt - nn2(days - x))
days -= d[i]
cnt -= nn2(d[i])
i += 1
return ans
def main():
n, x = ria()
d = ria()
print(solve(n, x, d))
main()
|
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR WHILE VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
def getAp(n):
return n * (n + 1) // 2
n, x = (int(var) for var in sys.stdin.readline().strip().split())
months = [int(var) for var in sys.stdin.readline().strip().split()]
months += months
hugs, days = [(0) for _ in range(2 * n)], [(0) for _ in range(2 * n)]
hugs[-1], days[-1] = getAp(months[-1]), months[-1]
for i in reversed(range(2 * n - 1)):
hugs[i] = hugs[i + 1] + getAp(months[i])
days[i] += days[i + 1] + months[i]
days.append(0)
hugs.append(0)
maxHugs = 0
for invx in reversed(range(2 * n)):
l, r = 0, invx
offset, store = days[invx + 1], None
while l <= r:
mid = (l + r) // 2
dayCalc = days[mid] - offset
if dayCalc == x:
store = mid
break
elif dayCalc < x:
store = mid
r = mid - 1
else:
l = mid + 1
if store is None:
maxHugs = max(maxHugs, getAp(months[invx]) - getAp(months[invx] - x))
else:
tempHugs = hugs[store] - hugs[invx + 1]
daysLeft = x - (days[store] - offset)
if store - 1 >= 0:
tempHugs += getAp(months[store - 1]) - getAp(months[store - 1] - daysLeft)
else:
maxHugs = max(maxHugs, tempHugs)
break
maxHugs = max(maxHugs, tempHugs)
print(maxHugs)
|
IMPORT FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NONE WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = lambda: sys.stdin.readline().strip()
ipnut = input
n, x = map(int, input().split())
d = list(map(int, input().split()))
d = d + d
d.reverse()
pref = [0]
pref1 = [0]
for i in range(n * 2):
pref.append(pref[-1] + d[i])
pref1.append(pref1[-1] + d[i] * (d[i] + 1) // 2)
l = 0
r = 1
ans = x
for i in range(n):
l = i
while r <= 2 * n and pref[r] - pref[l] <= x:
r += 1
r -= 1
dx = x - (pref[r] - pref[l])
ans = max(ans, pref1[r] - pref1[l] + dx * (2 * d[r] - dx + 1) // 2)
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def sum_to_n(v):
return v * (v + 1) // 2
def search(f, l, r, i, x):
m = (l + r) // 2
if m >= 1 and f[i] - f[m - 1] >= x and f[i] - f[m] <= x:
return m
elif m == 0 and f[i] >= x and f[i] - f[m] <= x:
return m
elif m >= 1 and f[i] - f[m - 1] <= x:
return search(f, l, m, i, x)
elif f[i] - f[m] > x:
return search(f, m + 1, r, i, x)
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a = a + a
n = len(a)
f = [a[0]]
for i in range(1, n):
f.append(f[i - 1] + a[i])
g = [sum_to_n(a[0])]
for i in range(1, n):
g.append(g[i - 1] + sum_to_n(a[i]))
ans = 0
for i in range(n):
if f[i] < x:
continue
j = search(f, 0, i, i, x)
res = g[i] - g[j]
r = x - (f[i] - f[j])
res += sum_to_n(a[j]) - sum_to_n(a[j] - r)
ans = max(ans, res)
print(ans)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR IF VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import stdin, stdout
nsum = lambda x: x * (x + 1) >> 1
n, x = map(int, stdin.readline().split())
d = list(map(int, stdin.readline().split()))
presum_hugs = [nsum(d[0])]
presum_days = [d[0]]
for i in range(1, n):
presum_hugs.append(presum_hugs[-1] + nsum(d[i]))
presum_days.append(presum_days[-1] + d[i])
for i in range(n):
presum_hugs.append(presum_hugs[-1] + nsum(d[i]))
presum_days.append(presum_days[-1] + d[i])
ans = 0
for start in range((n << 1) - 1, n - 1, -1):
hi = start
lo = hi - n + 1
while lo + 1 < hi:
mid = lo + hi >> 1
if presum_days[start] - presum_days[mid - 1] > x:
lo = mid
if presum_days[start] - presum_days[mid - 1] == x:
break
else:
hi = mid - 1
if presum_days[start] - presum_days[hi - 1] >= x:
lo = hi
temp = presum_hugs[start] - presum_hugs[lo - 1]
extra = presum_days[start] - presum_days[lo - 1] - x
if extra > 0:
temp -= nsum(extra)
ans = max(ans, temp)
stdout.write(str(ans) + "\n")
|
ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, k = map(int, input().split())
l = [int(x) for x in input().split()]
l = l + l
pre1 = [0] * (2 * n + 1)
pre2 = [0] * (2 * n + 1)
for i in range(1, 2 * n + 1):
pre1[i] = pre1[i - 1] + l[i - 1]
pre2[i] = pre2[i - 1] + l[i - 1] * (l[i - 1] + 1) // 2
mx = 0
for i in range(2 * n, n, -1):
low = 1
high = i
c = i
while low <= high:
mid = (low + high) // 2
if pre1[i] - pre1[mid] >= k:
low = mid + 1
else:
high = mid - 1
c = mid
t = pre2[i] - pre2[c - 1]
nd = pre1[i] - pre1[c - 1]
t -= (nd - k) * (nd - k + 1) // 2
mx = max(mx, t)
print(mx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = [int(a) for a in input().split()]
d = [int(a) for a in input().split()]
d += d
i = n
j = n
s = 0
ans = 0
hug = 0
while s < x:
i -= 1
hug += d[i] * (d[i] + 1) // 2
s += d[i]
while j < len(d):
while s < x and j < len(d):
s += d[j]
hug += d[j] * (d[j] + 1) // 2
j += 1
while s - d[i] >= x:
s -= d[i]
hug -= d[i] * (d[i] + 1) // 2
i += 1
rm = s - x
hugs = hug - rm * (rm + 1) // 2
ans = max(ans, hugs)
s -= d[i]
hug -= d[i] * (d[i] + 1) // 2
i += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
input = __import__("sys").stdin.readline
n, x = map(int, input().split())
lis = list(map(int, input().split()))
lis = lis + lis
pre = [0] * (2 * n + 5)
hug = [0] * (2 * n + 5)
pre[1] = lis[0]
hug[1] = lis[0] * (lis[0] + 1) // 2
for i in range(1, 2 * n):
pre[i + 1] = pre[i] + lis[i]
hug[i + 1] = hug[i] + lis[i] * (lis[i] + 1) // 2
ans = 0
for i in range(n + 1, 2 * n + 1):
l = 0
r = i
while l <= r:
mid = l + (r - l) // 2
day = pre[i] - pre[mid]
if day < x:
r = mid - 1
else:
l = mid + 1
tmp = hug[i] - hug[l]
rem = x - pre[i] + pre[l]
lef = pre[l] - pre[l - 1]
tmp += hug[l] - hug[l - 1] - (lef - rem) * (lef - rem + 1) // 2
ans = max(ans, tmp)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = list(map(int, input().split()))
a = [(i * (i + 1) // 2) for i in d]
inf = 100000000000
ans = 0
now1 = inf
now2 = 0
add1 = 0
add2 = 0
for i in range(n - 1, -1, -1):
if now1 == inf or now1 == i + 1:
check = x
now1 = inf
now2 = 0
add1 = 0
add2 = 0
if check < d[i]:
now2 = 0
add1 = check
add2 = (2 * d[i] - check + 1) * check // 2
else:
now1 = i
now2 = a[i]
check -= d[i]
while check >= d[now1 - 1]:
check -= d[now1 - 1]
now2 += a[now1 - 1]
now1 -= 1
add1 = check
add2 = (2 * d[now1 - 1] - check + 1) * check // 2
else:
check = add1 + d[i + 1]
add1 = 0
add2 = 0
now2 -= a[i + 1]
if check < d[now1 - 1]:
add1 = check
add2 = (2 * d[now1 - 1] - check + 1) * check // 2
else:
while check >= d[now1 - 1]:
check -= d[now1 - 1]
now2 += a[now1 - 1]
now1 -= 1
add1 = check
add2 = (2 * d[now1 - 1] - check + 1) * check // 2
ans = max(now2 + add2, ans)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR WHILE VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = sys.stdin.readline
def ceil(x):
if x != int(x):
x = int(x) + 1
return x
def swaparr(arr, a, b):
temp = arr[a]
arr[a] = arr[b]
arr[b] = temp
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def nCr(n, k):
if k > n - k:
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
def upper_bound(a, x, lo=0, hi=None):
if hi == None:
hi = len(a)
while lo < hi:
mid = (lo + hi) // 2
if a[mid] < x:
lo = mid + 1
else:
hi = mid
return lo
def primefs(n):
primes = {}
while n % 2 == 0 and n > 0:
primes[2] = primes.get(2, 0) + 1
n = n // 2
for i in range(3, int(n**0.5) + 2, 2):
while n % i == 0 and n > 0:
primes[i] = primes.get(i, 0) + 1
n = n // i
if n > 2:
primes[n] = primes.get(n, 0) + 1
return primes
def power(x, y, p):
res = 1
x = x % p
if x == 0:
return 0
while y > 0:
if y & 1 == 1:
res = res * x % p
y = y >> 1
x = x * x % p
return res
def swap(a, b):
temp = a
a = b
b = temp
return a, b
def find(x, link):
p = x
while p != link[p]:
p = link[p]
while x != p:
nex = link[x]
link[x] = p
x = nex
return p
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x, y = swap(x, y)
if x != y:
size[x] += size[y]
link[y] = x
def sieve(n):
prime = [(True) for i in range(n + 1)]
p = 2
while p * p <= n:
if prime[p] == True:
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
return prime
MAXN = int(100000.0 + 5)
def spf_sieve():
spf[1] = 1
for i in range(2, MAXN):
spf[i] = i
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, ceil(MAXN**0.5), 2):
if spf[i] == i:
for j in range(i * i, MAXN, i):
if spf[j] == j:
spf[j] = i
def factoriazation(x):
ret = {}
while x != 1:
ret[spf[x]] = ret.get(spf[x], 0) + 1
x = x // spf[x]
return ret
def int_array():
return list(map(int, input().strip().split()))
def float_array():
return list(map(float, input().strip().split()))
def str_array():
return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float("inf")
NINF = -float("inf")
n, x = int_array()
a = int_array()
a += a
i = 0
j = n - 1
ans = 0
cnt = sum(a) // 2
val = 0
for pk in a:
val += pk * (pk + 1) // 2
val //= 2
while j < 2 * n:
if cnt - a[i] >= x:
cnt -= a[i]
val -= a[i] * (a[i] + 1) // 2
i += 1
else:
not_take = cnt - x
not_val = not_take * (not_take + 1) // 2
ans = max(ans, val - not_val)
j += 1
if j < 2 * n:
cnt += a[j]
val += a[j] * (a[j] + 1) // 2
print(ans)
|
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF NUMBER NONE IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR DICT WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
a = list(map(int, input().split()))
a = a * 2
l, r, ans = 0, 1, 0
su = a[0]
dp = a[0] * (a[0] + 1) // 2
while r <= 2 * n:
if su >= x:
st = l
while su - a[l] >= x:
su = su - a[l]
dp = dp - a[l] * (a[l] + 1) // 2
l = l + 1
otv = dp
otv = otv - (su - x) * (su - x + 1) // 2
ans = max(ans, otv)
su = su - a[l]
dp = dp - a[l] * (a[l] + 1) // 2
l = l + 1
if r >= 2 * n:
break
su = su + a[r]
dp = dp + a[r] * (a[r] + 1) // 2
r = r + 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def Sum(a):
return a * (a + 1) // 2
m, x = map(int, input().split())
month = list(map(int, input().split())) * 2
ans, days, start = 0, 0, 0
hugs = 0
for i in range(len(month)):
hugs += Sum(month[i])
days += month[i]
while days > x:
if days - month[start] < x:
break
days -= month[start]
hugs -= Sum(month[start])
start += 1
diff = max(0, days - x)
ans = max(ans, hugs - Sum(diff))
print(ans)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.buffer.readline())
def MI():
return map(int, sys.stdin.buffer.readline().split())
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def BI():
return sys.stdin.buffer.readline().rstrip()
def SI():
return sys.stdin.buffer.readline().rstrip().decode()
def li():
return [int(i) for i in input().split()]
def lli(rows):
return [li() for _ in range(rows)]
def si():
return input()
def ii():
return int(input())
def ins():
return input().split()
n, x = MI()
days = LI()
vals = [(x * (x + 1) // 2) for x in days]
ans, temp = 0, 0
i, j, rem = 0, 0, x
for i in range(n):
while rem > days[j]:
rem -= days[j]
temp += vals[j]
j = (j + 1) % n
if rem == days[j]:
ans = max(ans, temp + vals[j])
if i != j:
rem += days[i]
temp -= vals[i]
else:
j = (j + 1) % n
elif i == j:
left = days[i] - rem
curr = vals[i] - left * (left + 1) // 2
ans = max(ans, curr)
j = (j + 1) % n
else:
shift = min(days[i] - 1, days[j] - rem)
change = (shift + rem) * (shift + rem + 1) // 2 - shift * (shift + 1) // 2
ans = max(ans, temp + change)
rem += days[i]
temp -= vals[i]
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
arr = list(map(int, input().split()))
arr += arr
prefix = []
prefix1 = []
Sum = 0
for i in arr:
Sum += i
prefix.append(Sum)
Sum = 0
for j in arr:
Sum += j * (j + 1) // 2
prefix1.append(Sum)
ans = 0
for i in range(n * 2):
A = prefix[i] - x
if A <= 0:
ans = prefix1[i]
elif arr[i] >= x:
jj = prefix1[i] - (arr[i] - x) * (arr[i] - x + 1) // 2
if i - 1 >= 0:
jj -= prefix1[i - 1]
ans = max(ans, jj)
else:
l = 0
r = i
Ans = i
while l <= r:
mid = (l + r) // 2
if prefix[mid] <= A:
Ans = mid
l = mid + 1
else:
r = mid - 1
B = prefix[i] - prefix[Ans] - x
ans = max(ans, prefix1[i] - prefix1[Ans] - B * (B + 1) // 2)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def right_m(me, num):
k = min(me, num)
return k * (k + 1) // 2
def left_m(me, num):
k = me
if me <= num:
return k * (k + 1) // 2
l = me - num
return k * (k + 1) // 2 - l * (l + 1) // 2
def ans(lm, rm, num):
if num <= lm:
return left_m(lm, num)
ans = right_m(rm, num)
num -= rm
if num > 0:
ans += left_m(lm, num)
return ans
n, x = map(int, input().split())
lst = list(map(int, input().split()))
daysnum = [0] * n * 2
ansnum = [0] * n * 2
daysnum[0] = lst[0]
ansnum[0] = (lst[0] + 1) * lst[0] // 2
for i in range(1, 2 * n):
daysnum[i] = daysnum[i - 1] + lst[i % n]
ansnum[i] = ansnum[i - 1] + (lst[i % n] + 1) * lst[i % n] // 2
leftnum = 0
rightnum = 1
maxans = 0
while leftnum < n and rightnum < 2 * n:
if leftnum == rightnum:
rightnum += 1
continue
ihave = x - daysnum[rightnum - 1] + daysnum[leftnum]
if ihave < 0:
leftnum += 1
continue
ansnow = ansnum[rightnum - 1] - ansnum[leftnum]
ansnow += ans(lst[leftnum % n], lst[rightnum % n], ihave)
maxans = max(maxans, ansnow)
rightnum += 1
print(maxans)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = [int(i) for i in input().split()]
d += d
ans, spent, end, ss = -1, 0, 0, 0
for i in range(0, n):
while spent < x:
check = d[end]
spent += check
ss += check * (check + 1) // 2
end += 1
more = spent - x
ans = max(ans, ss - more * (more + 1) // 2)
spent -= d[i]
ss -= d[i] * (d[i] + 1) // 2
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
D = list(map(int, input().split()))
D += D
D = D[::-1]
Ans = []
d = 0
p = 0
q = -1
tot = 0
fin = []
for i in D:
Ans.append(i * (i + 1) // 2)
while p < 2 * n and q < 2 * n:
q += 1
while p < 2 * n and q < 2 * n and d + D[p] < x:
d += D[p]
tot += Ans[p]
p += 1
if p == q:
k = D[p] - x + d
tot += Ans[p] - k * (k + 1) // 2
fin.append(tot)
d = 0
tot = 0
p += 1
elif p < 2 * n and q < 2 * n:
k = D[p] - x + d
tot += Ans[p] - k * (k + 1) // 2
fin.append(tot)
d -= min(D[q], d)
tot -= Ans[q]
tot -= Ans[p] - k * (k + 1) // 2
print(max(fin))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
arr = 2 * num2
n = num1[0]
x = num1[1]
pref1 = [arr[0] * (arr[0] + 1) // 2]
pref2 = [arr[0]]
for i in range(1, 2 * n):
s = arr[i] * (arr[i] + 1) // 2
pref1.append(pref1[-1] + s)
pref2.append(pref2[-1] + arr[i])
i = 2 * n - 1
max1 = 0
while i >= n:
l = 0
r = i
ans = i
while l <= r:
mid = (l + r) // 2
if pref2[i] - pref2[mid] < x:
ans = mid
r = mid - 1
else:
l = mid + 1
b = pref2[i] - pref2[ans - 1] - x
c = b * (b + 1) // 2
d = pref1[i] - pref1[ans - 1] - c
max1 = max(max1, d)
i -= 1
print(max1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def f(n):
return n * (n + 1) // 2
def rf(n, k):
return f(n) - f(n - k)
def search(a: list, x: int) -> int:
n = len(a)
i = 0
j = n // 2
while j >= 1:
while i + j < n and a[i + j] <= x:
i += j
j //= 2
return i
n, x = map(int, input().split())
d = list(map(int, input().split()))
a = [0]
b = [0]
for y in d:
a += (y + a[-1],)
b += (f(y) + b[-1],)
l = d[-1]
i = 0
while l < x:
a += (d[i] + a[-1],)
b += (f(d[i]) + b[-1],)
l += d[i]
i += 1
ans1 = 0
for i in range(n):
z = x - d[i]
if z <= 0:
ans1 = max(ans1, f(x))
continue
t = a[i + 1] + z
j = search(a, t)
if a[j] < t:
j += 1
k = a[j] - t
ans1 = max(ans1, b[j] - b[i] - rf(d[(j - 1) % n], k))
d = d[::-1]
a = [0]
b = [0]
for y in d:
a += (y + a[-1],)
b += (f(y) + b[-1],)
l = d[-1]
i = 0
while l < x:
a += (d[i] + a[-1],)
b += (f(d[i]) + b[-1],)
l += d[i]
i += 1
ans2 = 0
for i in range(n):
z = x - d[i]
if z <= 0:
ans2 = max(ans2, rf(d[i], x))
continue
t = a[i + 1] + z
j = search(a, t)
if a[j] < t:
j += 1
k = a[j] - t
ans2 = max(ans2, b[j] - b[i] - f(k))
print(max(ans1, ans2))
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = list(map(int, input().split()))
d = list(map(int, input().split()))
accum = 3 * n * [0]
accum2 = 3 * n * [0]
for i in range(3 * n):
if i > 0:
accum[i] = accum[i - 1]
accum2[i] = accum2[i - 1]
accum[i] += (d[i % n] + 1) * d[i % n] // 2
accum2[i] += d[i % n]
ans = 0
temp_ans = (d[0] + 1) * d[0] // 2
j = 0
days = d[0]
for i in range(n):
while days < x:
j += 1
days += d[j % n]
temp_ans += (d[j % n] + 1) * d[j % n] // 2
dif = days - x
if dif == 0:
ans = max(temp_ans, ans)
else:
ans = max(temp_ans - (dif + 1) * dif // 2, ans)
days -= d[i]
temp_ans -= (d[i] + 1) * d[i] // 2
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
s = [int(x) for x in input().split()]
s = s + s
con = []
pre = [0]
ct = [0]
for i in range(0, len(s)):
tt = s[i] * (s[i] + 1) // 2
con.append(tt)
for i in range(0, len(con)):
pre.append(pre[i] + con[i])
ct.append(ct[i] + s[i])
pre = pre + [pre[-1] + 10000]
ct = ct + [ct[-1] + 10000]
ans = x
for i in range(0, len(ct) - 1):
trg = ct[i] + x
low = i + 1
high = len(ct) - 1
temp = i + 1
while low <= high:
mid = low + high >> 1
if ct[mid] <= trg:
low = mid + 1
else:
temp = mid
high = mid - 1
c = pre[temp - 1] - pre[i]
dd = ct[temp - 1] - ct[i]
diff = x - dd
if diff >= 0:
if temp - 1 == i:
ele1 = s[i % n]
c += ele1 * (ele1 + 1) // 2
h = ele1 - diff
c -= h * (h + 1) // 2
else:
ele1 = s[i % n]
ele2 = s[(temp - 1) % n]
h = min(ele1 - 1, ele2 - diff)
c -= h * (h + 1) // 2
h2 = diff + h
c += h2 * (h2 + 1) // 2
ans = max(ans, c)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR LIST BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR LIST BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def findMonth(days, d):
if d <= days[0]:
return 0
low = 0
high = len(days)
while True:
mid = (low + high) // 2
if d <= days[mid] and (mid >= 0 and d > days[mid - 1]):
return mid
elif d > days[mid]:
low = mid + 1
else:
high = mid - 1
def s(x, y):
return (y - x + 1) * (x + y) // 2
def total(days, hugs, n, d, x):
currentDay = days[n]
startDay = (currentDay - d + 1) % (days[-1] + 1)
startMonth = findMonth(days, startDay)
leftOverDays = days[startMonth] - startDay + 1
startMonthDays = x[startMonth]
leftover = s(startMonthDays - leftOverDays + 1, startMonthDays)
if startMonth <= n:
return hugs[n] - hugs[startMonth] + leftover
else:
return hugs[n] + hugs[-1] - hugs[startMonth] + leftover
def f(arr, x):
totalDays = -1
days = []
totalHugs = 0
hugs = []
for i in arr:
totalDays += i
days.append(totalDays)
totalHugs += i * (i + 1) // 2
hugs.append(totalHugs)
m = 0
for i in range(len(arr)):
m = max(m, total(days, hugs, i, x, arr))
return m
nx = input().rstrip().split()
n = nx[0]
x = int(nx[1])
arr = input().rstrip().split()
arr = [int(i) for i in arr]
print(f(arr, x))
|
FUNC_DEF IF VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def sume(x):
return x * (x + 1) // 2
n, x = map(int, input().split())
z = list(map(int, input().split()))
m = len(z)
z = z + z
maxa = 0
pair = [-1, -1]
t1 = [(0) for i in range(m)]
for i in range(m, len(z)):
if i == m:
if z[m] >= x:
pair[0] = m
pair[1] = z[m] - x + 1
maxa = max(maxa, sume(z[i]) - sume(pair[1]))
t1[i - m] = sume(z[i]) - sume(pair[1] - 1)
else:
t = m
r = x
total = 0
while z[t] < r:
total += sume(z[t])
r -= z[t]
t -= 1
pair[0] = t
pair[1] = z[t] - r + 1
t1[i - m] = total + sume(z[t]) - sume(pair[1] - 1)
elif z[i] >= x:
pair[0] = i
pair[1] = z[i] - x + 1
t1[i - m] = sume(z[i]) - sume(pair[1] - 1)
else:
add = z[i]
if add <= z[pair[0]] - pair[1]:
re = pair[1]
pair[1] += add
t1[i - m] = t1[i - m - 1] + sume(z[i]) - (sume(pair[1] - 1) - sume(re - 1))
else:
add = z[i]
add -= z[pair[0]] - pair[1]
sub = sume(z[pair[0]]) - sume(pair[1] - 1)
ie = pair[0]
ie += 1
while add:
if z[ie] < add:
sub += sume(z[ie])
add -= z[ie]
ie += 1
else:
sub += sume(add - 1)
pair[0] = ie
pair[1] = add
add = 0
break
t1[i - m] = t1[i - m - 1] + sume(z[i]) - sub
print(max(t1))
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def find_max(i, ds, x, total):
integ = 0
resid = 0
yint = 0
yres = 0
m = 0
while x > 0:
d = ds[i]
if d <= x:
x -= d
integ += total[i]
yint += d
m += 1
else:
resid += d * (d + 1) // 2
resid -= (d - x) * (d - x + 1) // 2
yres = x
break
i -= 1
if i < 0:
i = len(ds) - 1
return integ, resid, yint, yres, m
n, x = [int(x) for x in input().split()]
ds = [int(x) for x in input().split()]
total = []
for d in ds:
total.append(d * (d + 1) // 2)
hugs = []
integ, resid, yint, yres, m = find_max(n - 1, ds, x, total)
hugs.append(integ + resid)
for i in range(n - 2, -1, -1):
integ -= total[i + 1]
yint -= ds[i + 1]
m -= 1
y = x - yint
resid = 0
yres = 0
j = (i - m + n) % n
while y > 0:
d = ds[j]
if d <= y:
y -= d
integ += total[j]
yint += d
m += 1
else:
resid += d * (d + 1) // 2
resid -= (d - y) * (d - y + 1) // 2
yres = y
break
j -= 1
if j < 0:
j = n - 1
hugs.append(integ + resid)
print(max(hugs))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
[N, X] = list(map(int, input().split()))
MONTHS = list(map(int, input().split()))
MONTHS = MONTHS + MONTHS
prefix_days = [0]
prefix_hugs = [0]
for num_days in MONTHS:
prefix_days.append(prefix_days[-1] + num_days)
num_hugs = num_days * (num_days + 1) // 2
prefix_hugs.append(prefix_hugs[-1] + num_hugs)
prefix_days.pop(0)
prefix_hugs.pop(0)
ans = -1
for right in range(len(MONTHS)):
idx = right
jump = len(MONTHS)
def nextIdx(idx):
if idx < 0:
return False
return prefix_days[right] - prefix_days[idx] < X
while jump != 0:
while nextIdx(idx - jump):
idx -= jump
jump //= 2
hugs_month_not_including_left = prefix_hugs[right] - prefix_hugs[idx]
days_taken = prefix_days[right] - prefix_days[idx]
days_this_month = X - days_taken
foo = MONTHS[idx] - days_this_month
hugs_left_month_subtract = foo * (foo + 1) // 2
hugs_left_month = MONTHS[idx] * (MONTHS[idx] + 1) // 2 - hugs_left_month_subtract
ans = max(ans, hugs_left_month + hugs_month_not_including_left)
print(ans)
|
ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR VAR VAR VAR VAR WHILE VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = sys.stdin.buffer.readline
def check(num):
for i in range(n):
if values[i] >= num:
return True
return False
def calc():
curr = days[0]
j = -1
while curr <= x:
curr += days[j]
j -= 1
left = curr - x
left = left * (left + 1) // 2
a = pref[0] + (pref[-1] - pref[j])
ans = a - left
values[0] = ans
j += 1
for i in range(1, n):
curr += days[i]
curr -= days[j]
while curr > x:
j += 1
curr -= days[j]
curr = max(curr, 0)
curr += days[j]
left = curr - x
left = left * (left + 1) // 2
if j < 0:
a = pref[i] + (pref[-1] - pref[j - 1])
elif j == 0:
a = pref[i]
else:
a = pref[i] - pref[j - 1]
values[i] = a - left
n, x = map(int, input().split())
days = list(map(int, input().split()))
count = []
for i in days:
count.append(i * (i + 1) // 2)
prefix = [days[0]]
pref = [count[0]]
for i in range(1, n):
prefix.append(prefix[-1] + days[i])
pref.append(pref[-1] + count[i])
if x == sum(days):
print(pref[-1])
exit()
values = [0] * n
calc()
maxx = sum(count)
low = 0
high = 10**18
while low < high:
mid = (low + high) // 2
if check(mid):
low = mid + 1
else:
high = mid - 1
if check(low):
print(low)
else:
print(low - 1)
|
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def sa(b, k):
start = 0
j = 0
sum = 0
e = 0
f = -1
while j < len(b) and start < len(b) // 2:
if sum >= k:
r = sum - k
u = e - r * (r + 1) // 2
if u > f:
f = u
sum += -b[start]
e += -b[start] * (b[start] + 1) // 2
start += 1
else:
sum += b[j]
e += b[j] * (b[j] + 1) // 2
j += 1
return f
n, k = map(int, input().split())
b = list(map(int, input().split()))
for j in range(n):
b.append(b[j])
print(sa(b, k))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from itertools import accumulate
def binary_search(arr, v):
l = 0
r = len(arr) - 1
ans = 0
while l <= r:
m = l + (r - l) // 2
if arr[m] >= v:
ans = m
r = m - 1
else:
l = m + 1
return ans
m, x = map(int, input().split())
arr = list(map(int, input().split()))
arr = arr[:] + arr[:]
m_length = list(accumulate(arr))
m_hugs = [0] * len(m_length)
for i in range(len(m_length)):
m_hugs[i] = arr[i] * (arr[i] + 1) // 2
m_hugs = list(accumulate(m_hugs))
ans = 0
for i in range(m):
end = -i - 1
start = binary_search(m_length, m_length[-i - 1] - x + 1)
remainder_day = x - (m_length[end] - m_length[start])
arrival = arr[start] - remainder_day + 1
start_hugs = (arrival + arr[start]) * (arr[start] - arrival + 1) // 2
total_hugs = start_hugs + m_hugs[end] - m_hugs[start]
ans = max(ans, total_hugs)
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def _sum(f, t):
return t * (t + 1) // 2 - f * (f - 1) // 2
n, x = map(int, input().split())
a = list(map(int, input().split()))
a += a
l = r = n
lf = -1
total = x
curr = 0
while total:
lf = max(a[l] - total + 1, 1)
curr += _sum(lf, a[l])
total -= a[l] - lf + 1
if total:
l -= 1
sol = curr
while r + 1 < 2 * n:
r += 1
curr += _sum(1, a[r])
total -= a[r]
while total < 0:
if a[l] - lf + 1 == -total:
curr -= _sum(lf, a[l])
total = 0
lf = 1
l += 1
elif a[l] - lf + 1 > -total:
curr -= _sum(lf, lf - total - 1)
lf -= total
total = 0
else:
curr -= _sum(lf, a[l])
total += a[l] - lf + 1
lf = 1
l += 1
sol = max(sol, curr)
print(sol)
|
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR WHILE VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def su(x, y):
a = y * (y + 1) // 2
b = x * (x - 1) // 2
return a - b
n, x = map(int, input().split())
mas = list(map(int, input().split()))
for i in range(n):
mas.append(mas[i])
r = n - 1
l = n - 1
suma = 0
ans = 0
maxi = 0
while suma <= x:
suma += mas[l]
ans += su(1, mas[l])
l -= 1
l += 1
suma -= mas[l]
ans -= su(1, mas[l])
r += 1
suma += mas[r]
ans += su(1, mas[r])
for i in range(n):
while suma > x:
l += 1
suma -= mas[l]
ans -= su(1, mas[l])
if suma == x:
now = ans
else:
now = ans + su(mas[l] - (x - suma - 1), mas[l])
maxi = max(maxi, now)
r += 1
if r != 2 * n:
suma += mas[r]
ans += su(1, mas[r])
print(maxi)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def rangesum(i, j):
return int((j - i + 1) * (i + j) / 2)
n, x = list(map(int, input().split(" ")))
D = list(map(int, input().split(" ")))
maximum = max(D)
hugs = 0
i = 0
i_days = None
while True:
if D[i] >= x:
hugs += int((D[i] + (D[i] - x + 1)) / 2 * x)
i_days = x
break
else:
hugs += int(D[i] * (D[i] + 1) / 2)
x -= D[i]
i -= 1
maxHugs = hugs
for j in range(1, n):
hugs += int(D[j] * (D[j] + 1) / 2)
if i_days >= D[j]:
hugs -= rangesum(D[i] - i_days + 1, D[i] - i_days + D[j])
i_days -= D[j]
else:
hugs -= rangesum(D[i] - i_days + 1, D[i])
i += 1
y = D[j] - i_days
while True:
if D[i] >= y:
i_days = D[i] - y
hugs -= rangesum(1, y)
break
else:
y -= D[i]
hugs -= rangesum(1, D[i])
i += 1
maxHugs = max(hugs, maxHugs)
print(int(maxHugs))
|
FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE WHILE NUMBER IF VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR WHILE NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def main():
n, x = map(int, input().split())
d = list(map(int, input().split()))
all_ob = list(map(lambda di: di * (di + 1) // 2, d))
current_period = 0
start_month = 0
while current_period + d[start_month] < x:
current_period += d[start_month]
start_month -= 1
z = x - current_period
start_month_ob = z * (2 * d[start_month] - z + 1) // 2
sum_ob = 0
for i in range(start_month + 1, 1):
sum_ob += all_ob[i]
best_ans = start_month_ob + sum_ob
for i in range(1, n):
current_period += d[i]
lm_ob = d[i] * (d[i] + 1) // 2
sum_ob += lm_ob
while current_period > x:
start_month += 1
current_period -= d[start_month]
sum_ob -= all_ob[start_month]
z = x - current_period
start_month_ob = z * (2 * d[start_month] - z + 1) // 2
best_ans = max(best_ans, start_month_ob + sum_ob)
print(best_ans)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
l = list(map(int, input().split()))
l *= 2
num = 0
ans = 0
val = 0
j = 0
for i in range(n):
while num < x:
num += l[j]
val += l[j] * (l[j] + 1) // 2
j += 1
if j == n:
j = 0
ans = max(ans, val - (num - x) * (num - x + 1) // 2)
num -= l[i]
val -= l[i] * (l[i] + 1) // 2
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import stdin, stdout
rr = lambda: input().strip()
rri = lambda: int(rr())
rrm = lambda: [int(x) for x in rr().split()]
def sol():
n, td = rrm()
v = rrm()
res = 0
curr = 0
i, j = 0, 0
while j < 2 * n:
if td > 0:
curr += v[j % n] * (v[j % n] + 1) // 2
td -= v[j % n]
j += 1
else:
while td + v[i % n] < 0:
curr -= v[i % n] * (v[i % n] + 1) // 2
td += v[i % n]
i += 1
x = -td
res = max(res, curr - x * (x + 1) // 2)
curr -= v[i % n] * (v[i % n] + 1) // 2
td += v[i % n]
i += 1
print(res)
return
sol()
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def sm(a, b):
val = (a + b) * (b - a + 1) // 2
return val
n, x = [int(x) for x in input().split()]
d = [int(x) for x in input().split()] * 2
mx, i, j, day, hug = 0, 0, 0, 0, 0
while i < n:
if day + d[j] <= x:
day += d[j]
hug += sm(1, d[j])
j += 1
else:
mx = max(mx, hug + sm(d[j] - (x - day) + 1, d[j]))
hug -= sm(1, d[i])
day -= d[i]
i += 1
print(mx)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def hugs(m, d, N, X, D, md):
acc = 0
while True:
if X >= D[m] - (d - 1):
acc += D[m] * (D[m] + 1) // 2 - (d - 1) * d // 2
X -= D[m] - (d - 1)
m = 0 if m == N - 1 else m + 1
d = 1
else:
end = X + (d - 1)
acc += end * (end + 1) // 2 - (d - 1) * d // 2
d = end
break
if d == D[m]:
m = 0 if m == N - 1 else m + 1
d = 1
else:
d += 1
md[0] = m
md[1] = d
return acc
def arrival_date_to_leave_at_first_month_end(N, X, D):
m = 0
while True:
if X <= D[m]:
return [m, D[m] - (X - 1)]
else:
X -= D[m]
m = N - 1 if m == 0 else m - 1
N, X = map(int, input().split())
D = list(map(int, input().split()))
m, d = arrival_date_to_leave_at_first_month_end(N, X, D)
md = [0, 0]
best_hugs = hugs(m, d, N, X, D, md)
curr_hugs = best_hugs
for j in range(1, N):
hugs_to_add = hugs(j, 1, N, D[j], D, md)
hugs_to_remove = hugs(m, d, N, D[j], D, md)
m, d = md
curr_hugs = curr_hugs + hugs_to_add - hugs_to_remove
best_hugs = max(best_hugs, curr_hugs)
print(best_hugs)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR RETURN LIST VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def sum_(x):
return x * (x + 1) // 2
n, x = map(int, input().split())
arr = list(map(int, input().split()))
arr.extend(arr)
start = 0
window_sum = 0
days = 0
ans = 0
for i in arr:
window_sum += sum_(i)
days += i
while days > x:
window_sum -= sum_(arr[start])
days -= arr[start]
start += 1
if start > 0:
ans = max(
ans, window_sum + sum_(arr[start - 1]) - sum_(arr[start - 1] - x + days)
)
print(ans)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
readline = sys.stdin.readline
N, X = map(int, readline().split())
D = list(map(int, readline().split()))
AD = D + D + [0]
S = [(d * (d + 1) // 2) for d in D]
S = S + S + [0]
for i in range(1, 2 * N):
AD[i] += AD[i - 1]
S[i] += S[i - 1]
D = D + D + [0]
ans = 0
for r in range(N, 2 * N):
ng = -1
ok = r
while abs(ok - ng) > 1:
med = (ok + ng) // 2
if AD[r] - AD[med] < X:
ok = med
else:
ng = med
l = ok
res = S[r] - S[l - 1]
dd = D[l] - (X - (AD[r] - AD[l]))
res -= dd * (dd + 1) // 2
ans = max(ans, res)
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = list(map(int, input().split(" ")))
nums = list(map(int, input().split(" ")))
n += n
nums += nums
re = 0
left = 0
s = 0
day = 0
def awesomeFunc(x):
return (1 + x) * x // 2
for i, v in enumerate(nums):
s += awesomeFunc(v)
day += v
while day - nums[left] > x:
day -= nums[left]
s -= awesomeFunc(nums[left])
left += 1
re = max(re, s - awesomeFunc(day - x))
print(re)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def fsm(d):
return d * (d + 1) // 2
def rsm(x, y):
return (x + (x - y + 1)) * y // 2
N, K = map(int, input().split())
D = list(map(int, input().split()))[::-1]
D = D * 2
sm = 0
ssm = 0
j = 0
R = 0
for i in range(N):
if i > 0:
sm -= D[i - 1]
ssm -= fsm(D[i - 1])
while sm + D[j] <= K:
sm += D[j]
ssm += fsm(D[j])
j += 1
tr = ssm
tr += rsm(D[j], K - sm)
R = max(tr, R)
print(R)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import stdin
n, m = map(int, stdin.readline().strip().split())
s = list(map(int, stdin.readline().strip().split()))
def sum(n):
return n * (n + 1) // 2
s = s[::-1]
s = s + s + s
acum = [(0) for i in range(n + n + 10)]
acum[0] = s[0]
for i in range(len(acum)):
acum[i] = acum[i - 1] + s[i % n]
pon = 0
ans = 0
tot = 0
aux = 0
for i in range(n):
if i != 0:
tot -= s[i - 1]
aux -= sum(s[i - 1])
while tot < m:
tot += s[pon]
aux += sum(s[pon])
pon += 1
y = tot - m
ans = max(ans, aux - sum(y))
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, d = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
max_hugs = 0
start = n - 1
end = n - 1
days = 0
hugs = 0
while end >= 0:
while days + arr[start] < d:
hugs += arr[start] * (arr[start] + 1) // 2
days += arr[start]
start = (n + start - 1) % n
if days < d:
extra_days = arr[start] - (d - days)
extra_hugs = (
arr[start] * (arr[start] + 1) // 2 - extra_days * (extra_days + 1) // 2
)
max_hugs = max(max_hugs, hugs + extra_hugs)
hugs -= arr[end] * (arr[end] + 1) // 2
days -= arr[end]
end -= 1
print(max_hugs)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = sys.stdin.readline
def main():
N, X = [int(x) for x in input().split()]
D = [int(x) for x in input().split()]
def sum_up_to_n(n):
return n * (n + 1) // 2
D = D + D
ans = 0
cnt = 0
l = 2 * N - 1
tmp = 0
for r in range(2 * N - 1, -1, -1):
while l >= 0 and cnt < X:
cnt += D[l]
tmp += sum_up_to_n(D[l])
l -= 1
ans = max(ans, tmp - sum_up_to_n(cnt - X))
tmp -= sum_up_to_n(D[r])
cnt -= D[r]
print(ans)
main()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def solve(n, x, d):
b = [d[0]]
tmp = d[0] * (d[0] + 1) // 2
c = [tmp]
length = n
ans = 0
n *= 2
for i in range(1, n):
b.append(b[i - 1] + d[i % length])
tmp = d[i % length] * (d[i % length] + 1) // 2
c.append(tmp + c[i - 1])
for i in range(n):
l = 0
r = i
key = b[i] - x
if key < 0:
continue
while l < r:
mid = l + (r - l) // 2
tmp = b[i] - b[mid]
if tmp >= x:
l = mid + 1
else:
r = mid
cnts = c[i] - c[r - 1]
diff = b[i] - b[r - 1]
days = diff - x
cnts -= days * (days + 1) // 2
ans = max(cnts, ans)
return ans
def main():
n, x = list(map(int, input().split()))
d = list(map(int, input().split()))
ans = solve(n, x, d)
print(ans)
main()
|
FUNC_DEF ASSIGN VAR LIST VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def sm(x):
return x * (x + 1) // 2
def get_sum(l, r):
return sm(r) - sm(l - 1)
n, x = list(map(int, input().split()))
d = [int(i) for i in input().split()]
d = d[:] + d[:]
n *= 2
pre = [d[0]]
month, day, days, tot = n - 1, d[n - 1] + 1, 0, 0
ans = 0
for i in range(n - 1, -1, -1):
while days < x and month >= 0:
if day > 1:
cnt = min(x - days, day - 1)
tot += get_sum(day - cnt, day - 1)
days += cnt
day -= cnt
else:
month -= 1
day = d[month] + 1
ans = max(ans, tot)
tot -= get_sum(1, d[i])
days -= d[i]
print(ans)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def sum_first(di):
return di * (di + 1) // 2
n, x = list(map(int, input().split()))
n *= 2
d = tuple(map(int, input().split())) * 2
ans = 0
i = 0
j = 0
cur_ans = 0
total_days = 0
while j <= n:
if total_days < x:
if j == n:
break
cur_ans += sum_first(d[j])
total_days += d[j]
j += 1
else:
ans = max(ans, cur_ans - sum_first(total_days - x))
cur_ans -= sum_first(d[i])
total_days -= d[i]
i += 1
print(ans)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import stdin
input = stdin.readline
n, x = map(int, input().split())
arr = list(map(int, input().split()))
arr += arr
n = len(arr)
parr = []
p = 0
mc = 0
for i in reversed(range(n)):
j = i - mc
while j >= 0 and x - arr[j] >= 0:
d = arr[j]
mc += 1
p += d * (d + 1) // 2
x -= d
j -= 1
dl = 0
if j >= 0 and x:
d = arr[j]
dl = d - x
p += d * (d + 1) // 2 - dl * (dl + 1) // 2
x = 0
parr.append(p)
d = arr[i]
p -= d * (d + 1) // 2
mc -= 1
x += d
if dl:
d = arr[j]
p -= d * (d + 1) // 2 - dl * (dl + 1) // 2
x += d - dl
print(max(parr))
|
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR IF VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import stdin
n, x = [int(x) for x in stdin.readline().split()]
month = [int(x) for x in stdin.readline().split()] * 2
high = max(month)
xCur = x
total = 0
start = 0
end = 0
best = 0
while start < n and end < len(month) - 1:
while xCur >= 0 and end < len(month) - 1:
xCur -= month[end]
total += month[end] * (month[end] + 1) // 2
end += 1
tempTotal = total
while xCur < 0:
if -xCur <= month[start]:
tempTotal -= -xCur * (-xCur + 1) // 2
total -= month[start] * (month[start] + 1) // 2
xCur += month[start]
start += 1
else:
tempTotal -= month[start] * (month[start] + 1) // 2
total -= month[start] * (month[start] + 1) // 2
xCur += month[start]
start += 1
best = max(best, tempTotal)
print(best)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
arr += arr[:]
arr2 = [(i * (i + 1) // 2) for i in arr]
ans = 0
for now_month in range(n, n * 2):
if now_month == n:
last_month = now_month
count_obnim = 0
count_days = 0
while count_days + arr[last_month] <= x:
count_days += arr[last_month]
count_obnim += arr2[last_month]
last_month -= 1
dop_days = x - count_days
nodop_days = arr[last_month] - dop_days
dop_obnim = arr2[last_month] - nodop_days * (nodop_days + 1) // 2
count_days += dop_days
count_obnim += dop_obnim
else:
count_days += arr[now_month]
count_days -= dop_days
count_obnim += arr2[now_month]
count_obnim -= dop_obnim
while count_days > x:
count_days -= arr[last_month + 1]
count_obnim -= arr2[last_month + 1]
last_month += 1
dop_days = x - count_days
nodop_days = arr[last_month] - dop_days
dop_obnim = arr2[last_month] - nodop_days * (nodop_days + 1) // 2
count_days += dop_days
count_obnim += dop_obnim
ans = max(ans, count_obnim)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def dude(pp):
return (pp + 1) * pp // 2
def gift():
for _ in range(1):
n, x = list(map(int, input().split()))
days = list(map(int, input().split()))
diulei = max(days)
if diulei >= x:
yield (diulei + diulei - x + 1) * x // 2
else:
s, e = 0, 0
maxans = 0
front = []
fres = 0
curans = 0
tored = 0
while s <= n - 1:
if s >= 1:
fres -= days[s - 1]
curans -= dude(days[s - 1])
curans -= tored
while True:
if fres >= x:
fres -= days[(e - 1) % n]
e = (e - 1) % n
break
front.append(days[e])
fres += days[e]
if fres <= x:
curans += dude(days[e])
if fres == x:
tored = dude(days[e])
else:
pp = days[e]
xtemp = x - (fres - pp)
curans += (pp + pp - xtemp + 1) * xtemp // 2
tored = (pp + pp - xtemp + 1) * xtemp // 2
e = (e + 1) % n
maxans = max(curans, maxans)
s += 1
yield maxans
ans = gift()
print(*ans, sep="\n")
1, 2, 3, 4, 1, 1, 1, 2, 3, 1, 2, 3, 1
|
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR WHILE NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING EXPR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import stderr, stdin
def rl():
return [int(w) for w in stdin.readline().split()]
n, end_day = rl()
d = rl()
start_month = start_day = end_month = hugs = 0
while end_month < n and end_day >= d[end_month]:
hugs += d[end_month] * (d[end_month] + 1) // 2
end_day -= d[end_month]
end_month += 1
hugs += end_day * (end_day + 1) // 2
max_hugs = hugs
if end_month < n:
while start_month < n:
step = min(d[start_month] - start_day, d[end_month] - end_day)
hugs += step * (end_day - start_day)
start_day += step
end_day += step
if start_day >= d[start_month]:
start_day = 0
start_month += 1
if end_day >= d[end_month]:
end_day = 0
end_month += 1
if end_month >= n:
end_month = 0
if hugs > max_hugs:
max_hugs = hugs
print(max_hugs)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
from sys import stdin, stdout
def the_best_vacation(n, x, d):
i = j = days = hugs = res = 0
while j < 2 * n:
ci = i % n
pi = (i - 1 + n) % n
pj = j % n
if d[pj] >= x:
res = max(res, gethugs(d[pj] - x + 1, d[pj]))
j += 1
i = j
continue
r = x - days
if days + d[pj] > x:
if d[pi] > r:
res = max(res, hugs + gethugs(d[pi] - r + 1, d[pi]))
else:
res = max(res, hugs + gethugs(1, r))
days -= d[ci]
hugs -= gethugs(1, d[ci])
i += 1
else:
if days + d[pi] > x:
res = max(res, hugs + gethugs(d[pi] - r + 1, d[pi]))
days += d[pj]
hugs += gethugs(1, d[pj])
j += 1
return res
def gethugs(a, b):
return (a + b) * (b - a + 1) // 2
nx = list(map(int, stdin.readline().split()))
d = list(map(int, stdin.readline().split()))
stdout.write(str(the_best_vacation(nx[0], nx[1], d)) + "\n")
|
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR STRING
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = [int(y) for y in input().split()]
d = [int(y) for y in input().split()]
def getHugs(start, end):
return (start + end) * (end - start + 1) // 2
def getMonthDay(day):
lo = 0
hi = len(dCumu) - 1
while True:
m = (lo + hi) // 2
endOfMonth = dCumu[m]
if endOfMonth >= day and (m == 0 or dCumu[m - 1] < day):
break
elif endOfMonth > day:
hi = m - 1
else:
lo = m + 1
return m, d2[m] - (endOfMonth - day)
d2 = d + d
dCumu = [d2[0]]
for i in range(1, len(d2)):
dCumu.append(dCumu[-1] + d2[i])
totalHugsByMonthCumu = [(-1) for _ in range(len(d2))]
for i in range(len(d2)):
if i == 0:
totalHugsByMonthCumu[i] = getHugs(1, d2[i])
else:
totalHugsByMonthCumu[i] = getHugs(1, d2[i]) + totalHugsByMonthCumu[i - 1]
for endMonth in range(len(dCumu)):
if dCumu[endMonth] >= x:
break
res = 0
for month in range(endMonth, len(d) + endMonth):
startMonth, startDay = getMonthDay(dCumu[month] - x + 1)
total = (
getHugs(startDay, d2[startMonth])
+ totalHugsByMonthCumu[month]
- totalHugsByMonthCumu[startMonth]
)
res = max(res, total)
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, k = map(int, input().split())
s = map(int, input().split())
s = list(s)
s = s + s
count = SUM = 0
def f(a, b):
return (a + b) * (b - a + 1) // 2
for i, x in enumerate(s):
if count + x >= k:
break
count += x
SUM += f(1, x)
j = i
i = 0
MAX = -float("inf")
remain = s[0]
for j in range(j, len(s)):
count += s[j]
SUM += f(1, s[j])
count -= remain
SUM -= f(s[i] - remain + 1, s[i])
while i != j and count >= k:
i += 1
count -= s[i]
SUM -= f(1, s[i])
remain = k - count
SUM += f(s[i] - remain + 1, s[i])
count = k
MAX = max(MAX, SUM)
print(MAX)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = lambda: sys.stdin.readline().rstrip()
N, X = map(int, input().split())
A = [int(a) for a in input().split()][::-1] * 2 + [1] * 10
x = X
j = 0
s = 0
la = A[0]
ans = 0
for i in range(len(A)):
while j < len(A) - 1 and x >= la:
x -= la
s += la * (la + 1) // 2
j += 1
la = A[j]
if j == len(A):
break
s += x * (la + la - x + 1) // 2
la -= x
x = 0
ans = max(ans, s)
s -= A[i] * (A[i] + 1) // 2
x += A[i]
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER NUMBER BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def upper_bound(arr, l, r, x):
start, end = l, r
while l <= r:
m = l + (r - l) // 2
if arr[m] > x:
r = m - 1
else:
l = m + 1
if start <= l <= end:
return l
return -1
n, x = map(int, input().split())
a = list(map(int, input().split()))
a += a
n *= 2
cur = 0
cur2 = 0
b = []
c = []
for i in range(n):
cur += a[i]
cur2 += a[i] * (a[i] + 1) // 2
b.append(cur)
c.append(cur2)
ans = 0
for i in range(n - 1):
if b[i + 1] >= x:
z = upper_bound(b, 0, n, b[i + 1] - x)
cnt = c[i + 1] - c[z]
days = b[i + 1] - b[z]
extra = x - days
cnt += a[z] * (a[z] + 1) // 2
cnt -= (a[z] - extra) * (a[z] - extra + 1) // 2
ans = max(ans, cnt)
print(ans)
|
FUNC_DEF ASSIGN VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
def input():
return sys.stdin.readline().rstrip()
def sum_first_n_numbers(a):
return a * (a + 1) // 2
n, x = [int(i) for i in input().split()]
n = 2 * n
days_per_month = [int(i) for i in input().split()]
days_per_month = days_per_month + days_per_month
hugs = [sum_first_n_numbers(i) for i in days_per_month]
pre_sum_hugs = [0]
pre_sum_days = [0]
for days, hug in zip(days_per_month, hugs):
pre_sum_days.append(pre_sum_days[-1] + days)
pre_sum_hugs.append(pre_sum_hugs[-1] + hug)
left_partial = 0
right_partial = 0
best = 0
while True:
if right_partial == left_partial:
right_partial += 1
if right_partial == n:
break
in_between_days = pre_sum_days[right_partial] - pre_sum_days[left_partial + 1]
in_between_hugs = pre_sum_hugs[right_partial] - pre_sum_hugs[left_partial + 1]
d_left = days_per_month[left_partial]
d_right = days_per_month[right_partial]
cap = d_left + d_right + in_between_days
if cap < x:
right_partial += 1
elif cap >= x:
overflow = x - in_between_days
if overflow >= d_left:
if overflow >= d_right:
pending = overflow - d_right
additional = (
sum_first_n_numbers(d_right)
+ sum_first_n_numbers(d_left)
- sum_first_n_numbers(d_left - pending)
)
else:
additional = sum_first_n_numbers(d_right) - sum_first_n_numbers(
d_right - overflow
)
else:
additional = sum_first_n_numbers(d_left) - sum_first_n_numbers(
d_left - overflow
)
best = max(best, additional + in_between_hugs)
left_partial = left_partial + 1
print(best)
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
dd = d + d
def b2(k):
return k * (k + 1) // 2
end_pt = 0
days = 0
best = 0
cur_hugs = b2(dd[0])
while days + dd[end_pt] < x:
days += dd[end_pt]
end_pt += 1
cur_hugs += b2(dd[end_pt])
start_pt = 0
start_day = days + dd[end_pt] - x + 1
while start_day > dd[start_pt]:
start_day -= dd[start_pt]
cur_hugs -= b2(dd[start_pt])
start_pt += 1
cur_hugs -= b2(start_day - 1)
best = cur_hugs
if False:
print("Initial:")
print("dd = ", dd)
print("end_month = ", end_pt)
print("start_month = ", start_pt)
print("start_day = ", start_day)
print("cur_hugs = best = ", best)
while end_pt + 1 < len(dd):
end_pt += 1
cur_hugs += b2(dd[end_pt])
cur_hugs += b2(start_day - 1)
start_day += dd[end_pt]
while start_day > dd[start_pt]:
start_day -= dd[start_pt]
cur_hugs -= b2(dd[start_pt])
start_pt += 1
cur_hugs -= b2(start_day - 1)
best = max(best, cur_hugs)
print(best)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = sys.stdin.buffer.readline
def func(n):
return n * (n + 1) // 2
def solution():
n, x = map(int, input().split())
li = list(map(int, input().split()))
li += li
sumd = [0] * (2 * n + 1)
cntd = [0] * (2 * n + 1)
for i in range(2 * n - 1, -1, -1):
sumd[i] = sumd[i + 1] + func(li[i])
cntd[i] = cntd[i + 1] + li[i]
pos = 2 * n - 1
ans = 0
while pos >= n:
l = 0
r = pos
while l <= r:
mid = (l + r) // 2
if cntd[mid] - cntd[pos + 1] < x:
r = mid - 1
else:
beg = mid
l = mid + 1
temp = 0
if beg != pos:
temp += sumd[beg + 1] - sumd[pos + 1]
z = li[beg] - x + cntd[beg + 1] - cntd[pos + 1]
temp += func(li[beg]) - func(z)
ans = max(ans, temp)
pos -= 1
print(ans)
solution()
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
d = list(map(int, input().split()))
d = d + d
cumulative_days = [0]
cumulative_total = [0]
for i in d:
cumulative_days.append(cumulative_days[-1] + i)
cumulative_total.append(cumulative_total[-1] + i * (i + 1) // 2)
left = 1
right = 1
max_hugs = 0
while True:
if cumulative_days[right] - cumulative_days[left - 1] < x:
right += 1
if right == len(cumulative_days):
break
else:
left += 1
if cumulative_days[right] - cumulative_days[left - 1] < x:
extra_days = cumulative_days[right] - cumulative_days[left - 2] - x
num_hugs = (
cumulative_total[right]
- cumulative_total[left - 2]
- extra_days * (extra_days + 1) // 2
)
max_hugs = max(max_hugs, num_hugs)
print(max_hugs)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
def NSum(N):
return N * (N + 1) >> 1
N, K = map(int, input().split())
List = [int(x) for x in input().split()]
Days = [0]
Hugs = [0]
for i in range(2 * N):
Days.append(Days[-1] + List[i % N])
Hugs.append(Hugs[-1] + NSum(List[i % N]))
i = 0
j = 1
Max = 0
while i < N:
if Days[j] - Days[i] > K and Days[j] - Days[i + 1] >= K:
i += 1
elif Days[j] - Days[i] >= K and Days[j] - Days[i + 1] < K:
Max = max(Max, Hugs[j] - Hugs[i] - NSum(Days[j] - Days[i] - K))
i += 1
j += 1
else:
j += 1
print(Max)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
input = sys.stdin.readline
n, x = map(int, input().split())
a = [int(item) for item in input().split()]
a = a + a
cnt = 0
val = 0
l = 0
r = 0
left_idx = 0
ans = 0
while r < 2 * n:
cnt += a[r]
val += (a[r] + 1) * a[r] // 2
r += 1
if cnt < x:
continue
while cnt > x:
step = cnt - x
if a[l] - left_idx <= step:
cnt -= a[l] - left_idx
val -= (a[l] + 1) * a[l] // 2 - (left_idx + 1) * left_idx // 2
left_idx = 0
l += 1
else:
step = cnt - x
cnt = x
val -= (left_idx + step + 1) * (left_idx + step) // 2 - (
left_idx + 1
) * left_idx // 2
left_idx += step
ans = max(ans, val)
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
class Solution:
def __init__(self):
n, x = list(map(int, input().split()))
d = list(map(int, input().split()))
self.solve(n, x, d)
def f(self, n):
return int(n * (n + 1) / 2)
def getRange(self, a, l, r):
return a[r] - (0 if l == 0 else a[l - 1])
def calc(self, ad, sd, i, x, n):
l, r = 0, i
pos = None
while l <= r:
m = l + r >> 1
s = self.getRange(ad, m, i)
if s >= x:
pos, l = m, m + 1
else:
r = m - 1
if pos is not None:
days = self.getRange(ad, pos, i)
return self.getRange(sd, pos, i) - self.f(days - x)
else:
return self.getRange(sd, 0, i) + self.calc(
ad, sd, n - 1, x - self.getRange(ad, 0, i), n
)
def solve(self, n, x, d):
ad = [i for i in d]
sd = [self.f(i) for i in d]
for i in range(1, n):
ad[i] += ad[i - 1]
sd[i] += sd[i - 1]
res = 0
for i in range(0, n):
temp = self.calc(ad, sd, i, x, n)
res = max(res, temp)
print(res)
Solution()
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NONE WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
import sys
readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
def solve():
n, x = nm()
d = nl() * 2
f = [(x * (x + 1) // 2) for x in d]
for i in range(2 * n - 1):
f[i + 1] += f[i]
l = -1
s = sum(d[:n])
ans = 0
for r in range(n, 2 * n):
s += d[r]
while s > x:
l += 1
s -= d[l]
ans = max(
ans,
f[r]
- f[l]
+ d[l] * (d[l] + 1) // 2
- (d[l] - x + s) * (d[l] - x + s + 1) // 2,
)
print(ans)
return
solve()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
|
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.
They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.
The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.
You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan).
Please note that your trip should not necessarily begin and end in the same year.
-----Input-----
The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) β the number of months in the year and the number of days you can spend with your friend.
The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).
It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.
-----Output-----
Print one integer β the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.
-----Examples-----
Input
3 2
1 3 1
Output
5
Input
3 6
3 3 3
Output
12
Input
5 6
4 2 3 1 3
Output
15
-----Note-----
In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.
In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.
In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.
|
n, x = map(int, input().split())
a = list(map(int, input().split()))
l = r = 0
for i in range(n):
a.append(a[i])
def fuckit(x):
return (1 + x) * x // 2
ans = nowd = nows = 0
while r < 2 * n:
nowd += a[r]
nows += fuckit(a[r])
r += 1
while nowd - a[l] >= x:
nowd -= a[l]
nows -= fuckit(a[l])
l += 1
dif = max(0, nowd - x)
ans = max(ans, nows - fuckit(dif))
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.