#K39647. Minimum Size Subarray Sum
Minimum Size Subarray Sum
Minimum Size Subarray Sum
Given an array of positive integers and a target integer \(T\), your task is to find the minimum length of a contiguous subarray such that the sum of its elements is at least \(T\). If no such subarray exists, output 0.
A subarray is a contiguous section of an array. For instance, consider the array [2, 3, 1, 2, 4, 3]
and \(T = 7\); the subarray [4, 3]
has a sum of 7 and a length of 2, which is the minimum possible.
Input constraints: All numbers in the array are positive integers.
Note: In this problem, you need to design a solution that reads input from stdin
and writes the result to stdout
.
inputFormat
The input consists of three lines:
- The first line contains an integer representing the target \(T\).
- The second line contains an integer \(n\) denoting the number of elements in the array.
- The third line contains \(n\) space-separated positive integers, representing the array elements.
outputFormat
Output a single integer, which is the minimum length of a contiguous subarray whose sum is at least \(T\). If no such subarray exists, output 0.
## sample7
6
2 3 1 2 4 3
2