No.2601 Very Poor
タグ : / 解いたユーザー数 153
作問者 : 👑
amentorimaru
/ テスター :
cleantted
👑 Problem Statement
In a certain virtual space, restrictions may be imposed on avatars with too high a load.
Etowanyu-kun is trying to choose accessories to put on his avatar.
There are $N$ accessories, numbered from $1$ to $N$, displayed one by one in a circle on a table. Accessory $i+1$ is placed immediately to the left of accessory $i$, and accessory $1$ is placed immediately to the left of accessory $N$. The polygon count of accessory $i$ is $A_i$.
Etowanyu-kun wants to choose some consecutively arranged accessories among them and wear them, but if the total polygon count of the chosen accessories exceeds $X$, the avatar is judged to be high-load.
Find the maximum total polygon count when accessories are chosen so that the polygon count is as large as possible without being judged high-load.
Input
$N\ X$ $A_1 \ A_2 \ \dots A_N$
- All inputs are integers.
- $1 \le N \le 2\times 10^5$
- $1 \le A_i,X \le 10^9$
Output
Output the answer.
Sample
Sample 1
Input
5 11 4 5 7 3 3
Output
10
Viewed from above, the accessories are arranged as shown below.
Etowanyu-kun can obtain a polygon count of $7+3=10$ by choosing the consecutive accessories $3,4$.
He can also wear accessories with a polygon count of $3+3+4=10$ by choosing the consecutive accessories $4,5,1$. Note that $N$ and $1$ are also adjacent.
Any way of wearing accessories with a total greater than $10$ is not possible: for example, choosing the consecutive accessories $5,1,2$ gives a polygon count of $3+4+5=12$, which exceeds $X=11$ and is judged to be high-load.
Choosing accessories $1,3$ gives a total of $4+7=11$, but note that a choice in which the accessories are not consecutive is not allowed.
Sample 2
Input
6 70000 108686 107161 117224 117236 78936 112374
Output
0
There may be cases where nothing can be worn.
Sample 3
Input
10 100 17 32 47 68 11 18 83 37 91 78
Output
97
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。