#P1181. 数列分段 Section I
数列分段 Section I
Description
Given a sequence of length consisting of non-negative integers, split it into several consecutive segments such that the sum of each segment does not exceed (it can be equal to ). Find the minimum number of segments needed to meet the requirement.
Input Format
The first line contains two positive integers , representing the length of the sequence and the maximum allowed sum of each segment. The second line contains space-separated non-negative integers , as described.
Output Format
Output a single integer: the minimum number of segments.
5 6
4 2 4 5 1
3
Hint
For of the testdata, there is .
For of the testdata, there is .
For of the testdata, there are , is greater than the maximum element, and the sum of does not exceed .
Split the sequence as follows:
The sum of the first segment is , the sum of the nd segment is , and the sum of the rd segment is , all not exceeding . It can be proven that is the minimum number of segments.
Translated by ChatGPT 5
京公网安备 11011102002149号