#C11025. Minimum Size Subarray Sum

    ID: 40296 Type: Default 1000ms 256MiB

Minimum Size Subarray Sum

Minimum Size Subarray Sum

Given a target integer \(T\) and an array of \(n\) integers, your task is to find the length of the smallest contiguous subarray whose sum is at least \(T\). If no such subarray exists, output 0.

Example: For \(T=7\) and the array [2, 3, 1, 2, 4, 3], the answer is 2 because the subarray [4,3] adds to 7 which is the minimum possible length achieving the target.

Hint: A sliding window approach can be used to solve this problem efficiently in \(O(n)\) time.

inputFormat

The input is read from standard input (stdin) and has the following format:
The first line contains a single integer \(T\), the target sum.
The second line contains a single integer \(n\), the number of elements in the array.
The third line contains \(n\) space-separated integers representing the array elements.

For example:
7 6 2 3 1 2 4 3

outputFormat

Output a single integer to standard output (stdout), representing the length of the smallest contiguous subarray whose sum is at least \(T\). If no such subarray exists, output 0.

## sample
7
6
2 3 1 2 4 3
2