eolymp
bolt
Try our new interface for solving problems
Problems

Hotels Along the Croatian Coast

Hotels Along the Croatian Coast

Along the beautiful Adriatic coast, there are $n$ hotels. Each hotel has its cost in euros. Petr won $m$ euros in the lottery. Now he wants to buy a sequence of consecutive hotels one after another so that the sum of the costs of these consecutive hotels is as large as possible, but does not exceed $m$. You need to calculate this maximum possible total cost. \InputFile The first line contains two integers $n$ and $m~(1 \le n \le 3 \cdot 10^5, 1 \le m < 2^{31})$. The next line contains $n$ positive integers less than $10^6$, representing the costs of the hotels in the order they are located along the coast. \OutputFile Print the desired maximum cost (it will be greater than $0$ in all tests).
Time limit 1 second
Memory limit 128 MiB
Input example #1
5 12
2 1 3 4 5
Output example #1
12