K
is a sum you want to equal or be greater than in your window.
If you make an array of prefix sums, B
, then you're looking for B[left] <= B[right] - K
which means
that the sum of the window in your original array A
has to be >= K
.
Given B[right]
, you're looking for B[left]
such that B[left] <= B[right] - K
.
You need to use an increasing monotonic queue because with each new B[i]
, the larger elements on the
left won't work as candidates to make some future element B[j] >= B[i] + K
where j > i
.