#P1181. Minimum Contiguous Segments Partition
Minimum Contiguous Segments Partition
Minimum Contiguous Segments Partition
Given a sequence of positive integers \(A_1, A_2, \ldots, A_N\) of length \(N\) and an integer \(M\), the task is to partition the sequence into contiguous segments such that the sum of each segment does not exceed \(M\) (i.e. \(\sum_{i\in segment} A_i \le M\)). Determine the minimum number of segments required to satisfy this condition.
Note: It is guaranteed that each element \(A_i\) is not greater than \(M\), ensuring that partitioning is always possible.
inputFormat
The first line of input contains two positive integers \(N\) and \(M\) separated by a space.
The second line contains \(N\) positive integers \(A_1, A_2, \ldots, A_N\) separated by spaces.
outputFormat
Output a single integer representing the minimum number of contiguous segments into which the sequence can be partitioned so that the sum of each segment does not exceed \(M\).
sample
5 5
1 2 3 4 5
4