#P3514. Lollipop Segmentation

    ID: 16768 Type: Default 1000ms 256MiB

Lollipop Segmentation

Lollipop Segmentation

Byteasar runs a confectionery in Byteburg and has a very long lollipop composed of several segments. Each segment is of the same length and can be either strawberry-flavoured (costing \(2\) bythalers) or vanilla-flavoured (costing \(1\) bythaler). The overall price of a lollipop is the sum of its segments' values. Byteasar wishes to break the lollipop at the joints between segments to form one or more pieces (each piece is a contiguous block of segments) in such a way that among the resulting pieces there is at least one piece whose price is exactly \(k\) bythalers.

Your task is, given the lollipop and an integer \(k\), to decide if it is possible to break the lollipop (or leave it unbroken) so that one of the resulting contiguous pieces has a total price equal to \(k\). If it is possible, you must output one valid way of breaking it - that is, output the number of pieces together with the lengths of each piece (the pieces must be non-empty and in order). Note that if the whole lollipop's cost equals \(k\), then it is a valid solution (with no break needed).

Input format: The input consists of two lines. The first line contains two space-separated integers \(n\) and \(k\) \((1 \leq n, k \leq 10^5)\), where \(n\) is the number of segments and \(k\) is the target cost. The second line contains a string of length \(n\) consisting only of the characters s and v, where s represents a strawberry-flavoured segment (cost \(2\)) and v represents a vanilla-flavoured segment (cost \(1\)).

Output format: If it is impossible to obtain a contiguous piece with total cost exactly \(k\) by breaking the lollipop, output a single line with NO. Otherwise, on the first line output YES. On the second line, first output an integer \(p\) representing the number of pieces in your segmentation, followed by \(p\) positive integers which represent the lengths of each piece (in order). The sum of these \(p\) numbers must equal \(n\), and one of the pieces must have a total cost of exactly \(k\).

Note: Since every segment has a positive cost, if there exists any contiguous subsegment with cost \(k\), you can always form a segmentation so that this subsegment appears as one of the pieces. For example, if the valid subsegment is a prefix then you can split into two pieces; if it’s in the middle, split into three pieces, etc.

inputFormat

The first line contains two integers \(n\) and \(k\): the number of segments and the target cost.

The second line contains a string of length \(n\) consisting only of characters s and v (without spaces), where s corresponds to a strawberry segment (cost \(2\)) and v corresponds to a vanilla segment (cost \(1\)).

outputFormat

If it is impossible to obtain a contiguous piece with cost exactly \(k\), output a single line with NO.

Otherwise, on the first line output YES. On the second line, output an integer \(p\) representing the number of pieces, followed by \(p\) space-separated positive integers indicating the lengths of each piece (in order). These lengths should sum up to \(n\), and one of the pieces must have a total cost exactly equal to \(k\).

sample

5 8
svsvs
YES

1 5

</p>