Subarray Up To K


Problem Statement

Given an array aa of nn integers a1,a2,...,ana_1, a_2, ..., a_n, as well as an integer kk, determine the sum of the subarray which has a sum which is less than or equal to kk. There will always be a subarray with a sum of 00. If there is no subarray with sum less than or equal to kk then output −1-1.

Remember that a subarray is a selection of continuous elements of aa.

Input Format

Your first line will contain two space-separated integers nn and kk. Your next line will contain nn space-separated integers a1,...,ana_1, ..., a_n.

Output Format

You should output the largest subarray sum less than or equal to kk. If there is no subarray with sum less than or equal to kk then output −1-1.

Constraints

  • 1≤n≤1051 \leq n \leq 10^5
  • −109≤ai≤109-10^9 \leq a_i \leq 10^9
  • −109≤k≤109-10^9 \leq k \leq 10^9

Sample Cases

Input 1
6 13
100 -4 2 7 2 5
Output 1
12
Explanation 2

The subarray with sum of 1212 is [−4,2,7,2,5][-4, 2, 7, 2, 5].

Input 2
5 5
1 2 -4 2 5
Output 2
5
Explanation 2

The subarray with sum of 55 is [5][5].

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.