Fewest Bounded Pieces
Cut the array into the minimum number of contiguous pieces so each piece's sum is at most K. Print the minimum count, or −1 if some single element exceeds K.
Input: the first line has N and K; the second line has N positive integers.
Output: the minimum number of pieces, or −1.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ K ≤ 109
- 1 ≤ ai ≤ 1000
Sample Tests
Input 1
5 6 1 2 3 4 5
Output 1
3
Input 2
3 2 1 5 1
Output 2
-1
Discussion (opens after you solve — no spoilers before)
No comments yet.