Problems
Subsequence
Subsequence
A sequence an
of integers consists of n elements. For a given number k find a non-empty subsequence ai
, ai+1
, ... ai+m
of consecutive elements of the sequence an
, 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, -109
≤ k ≤ 109
) - number of elements in the sequence and the desired sum. The second line is followed by n integers ai
(-109
≤ ai
≤ 109
) - 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.
Input example #1
9 5 1 -2 2 -1 2 -1 3 -2 6
Output example #1
0