#C10960. Closest Subarray Sum

    ID: 40223 Type: Default 1000ms 256MiB

Closest Subarray Sum

Closest Subarray Sum

You are given an array of integers and a target integer \(T\). Your task is to find the sum of the contiguous subarray whose sum is closest to \(T\) in absolute difference.

Formally, given an array \(a_1,a_2,\ldots,a_n\) and a target \(T\), you need to choose indices \(i\) and \(j\) (with \(1 \le i \le j \le n\)) such that the absolute difference \(|(a_i+ a_{i+1}+\cdots+a_j)-T|\) is minimized. If there are multiple answers, output any one with the minimum difference.

inputFormat

The first line contains two integers \(n\) and \(T\) where \(n\) is the number of elements in the array and \(T\) is the target sum.

The second line contains \(n\) integers \(a_1,a_2,\ldots,a_n\), representing the array elements.

outputFormat

Output a single integer on a new line: the sum of the contiguous subarray that is closest to \(T\).

## sample
5 10
2 -1 2 3 4
10

</p>