You are on page 1of 1

The 2023 ICPC Programming Contest

University of Science, VNU-HCM


October 01, 2023

Problem B
Segments
Time Limit: 1 second
Memory Limit: 256 megabytes

Today, Prof. Minh gives you a problem about segments.


You are given a sequence of 𝑛 integers 𝐴 = (𝑎1 , 𝑎2 , . . . . , 𝑎𝑛 ) and an
integer 𝑚. A split of sequence 𝐴 into 𝑘 consecutive sub-segments is
represented by a sequence of integers:
0 = 𝑥0 < 𝑥1 < 𝑥2 <. . . . < 𝑥𝑘−1 < 𝑥𝑘 = 𝑛
in which the jth segment includes elements from 𝑎[𝑥𝑗−1 + 1] to 𝑎[𝑥𝑗 ].
For example, with 𝑛 = 11; 𝐴 = (9, −1, 2, −6, 1, 2, 3, −4, 3, 9, −4), if we split the sequence 𝐴
into 3 consecutive sub-segments:
𝑎[1. .5] = (9, −1, 2, −6, 1); 𝑎[6. .9] = (2, 3, −4, 3); 𝑎[10. . .11] = (9, −4)
then the sequence 𝑥[0. .3] is (0, 5, 9, 11).
Your task is to split the sequence 𝐴 into a minimum number of consecutive sub-segments such
that the sum of the elements in each segment does not exceed 𝑚.

Input
The first line contains two positive integers 𝑛, 𝑚 (𝑛 ≤ 105 ; 𝑚 ≤ 109 ).
The second line contains 𝑛 integers 𝑎1 , 𝑎2 , … , 𝑎𝑛 (|𝑎𝑖 | ≤ 109 ; 𝑖 = 1,2, … , 𝑛)
Note: It is guaranteed that there always exists a split satisfying the condition.

Output
The output contains only one integer 𝑘 - the minimum number of segments you can split.

Sample Input Sample Output


11 5 3
9 -1 2 -6 1 2 3 -4 3 9 -4

You might also like