Two pointer method
Problem
Given an array of N
positive numbers. Find in it the minimum number of consecutive numbers such that their sum is greater than K
.
Input
The first line contains the number
N
, the second -
K
(0<N<= 10
6, 0<=K<= 10
9). The third line contains the natural numbers of the sequence.
Imprint
Print the length of the smallest sequence of numbers whose sum is greater than
K
. If such a sequence is not found, then print
-1
.
Examples
# |
Input |
Output |
1 |
6
7
3 1 3 2 4 3
| 3 |