Subsequence
Medium
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
A sequence a[n]
of integers consists of n elements. For a given number k find a non-empty subsequence a[i]
, a[i+1]
, ... a[i+m]
of consecutive elements of the sequence a[n]
, such that the sum of its elements as close as possible to k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 500000, -10^9
≤ k ≤ 10^9
) - number of elements in the sequence and the desired sum. The second line is followed by n integers a[i]
(-10^9
≤ a[i]
≤ 10^9
) - the elements of the sequence.
Output
Print one number |k – l| (absolute difference of k – l), where l is the total sum on optimum segment of the sequence.
Examples
Input #1
Answer #1
Submissions 215
Acceptance rate 10%