#C2735. Minimum Subsequence Partition

    ID: 46084 Type: Default 1000ms 256MiB

Minimum Subsequence Partition

Minimum Subsequence Partition

Given a sequence of integers represented by an array \(A\) of length \(N\) and a target integer \(K\), partition the sequence into the minimum number of contiguous subsequences such that the sum of each subsequence is at least \(K\) at the moment it is formed. The partitioning is performed greedily: traverse the array and keep accumulating elements until adding the next element reaches or exceeds \(K\), then finalize that subsequence and start a new one. If there are remaining elements that do not reach \(K\) at the end, they form the final subsequence.

Your task is to implement a solution that reads input from standard input and outputs the total number of subsequences followed by each subsequence on a new line.

inputFormat

The input consists of a single line containing integers separated by spaces. The first integer is (N) (the number of elements in the array), the second is (K) (the target sum for each subsequence), followed by (N) integers representing the array (A). For example:

5 5 1 3 4 2 2

outputFormat

The output should first print the number of subsequences. Then, for each subsequence, print a line with its elements separated by a single space. For example:

2 1 3 4 2 2## sample

5 5 1 3 4 2 2
2

1 3 4 2 2

</p>