Shortest Wet Spell
hard
A meteorologist is studying daily rainfall patterns in a region. They have an array r where each value represents the amount of rain (in millimeters) collected on a particular day, which can be positive (actual rainfall), zero (no rain), or negative (water loss due to evaporation).
The meteorologist wants to identify the shortest consecutive period during which the total collected rainwater reaches at least th millimeters for water resource planning.
Given the daily rainfall measurements r and a threshold value th, return the length of the shortest streak of consecutive days that collected at least th millimeters of rain. If no such period exists, return -1. Input Format:
The first line contains two integers n (1 ≤ n ≤ 10^5) and th (1 ≤ th ≤ 10^9), denoting the size of array r and the threshold.
The second line contains n integers r[1], r[2], ..., r[n] denoting the elements of array r. (−10^5 ≤ ri ≤ 10^5)
Output Format:
Give the answer as a single integer.
Examples: