#C1694. Max Subarray Sum with Minimum Threshold
Max Subarray Sum with Minimum Threshold
Max Subarray Sum with Minimum Threshold
You are given an array of integers of length n along with an integer threshold k. Your task is to compute the maximum sum of any contiguous subarray such that the sum is at least k. If no contiguous subarray has a sum that is at least k, output 0.
Formally, let \(a_1, a_2, \ldots, a_n\) be the array, and let a subarray be defined by indices \(i\) and \(j\) (with \(1 \le i \le j \le n\)) with sum \(S = \sum_{t=i}^{j} a_t\). You are to find the maximum \(S\) such that \(S \ge k\). If no such \(S\) exists, output 0.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two space-separated integers, n and k, where n is the number of elements in the array and k is the threshold.
- The second line contains n space-separated integers representing the elements of the array.
outputFormat
Output a single integer to standard output (stdout) which is the maximum subarray sum that is at least k. If no such subarray exists, output 0.
## sample5 10
1 2 3 4 5
15