#P7938. Beautiful Bracket Arrays Partition
Beautiful Bracket Arrays Partition
Beautiful Bracket Arrays Partition
Given a bracket sequence s of length n and an integer m, partition the indices from 1 to n into 2*m strictly increasing arrays \(p_1, p_2, ..., p_{2m}\) such that every integer from 1 to n appears exactly once in these arrays. An array \(p = \{r_1, r_2, ..., r_k\}\) is called Beautiful if the bracket sequence \(s_{r_1}s_{r_2}...s_{r_k}\) forms a Regular Bracket Sequence (RBS).
The definition of a Regular Bracket Sequence is given by:
- \( () \) is a RBS.
- If \(A\) is a RBS, then \( (A) \) is also a RBS.
- If \(A\) and \(B\) are RBS, then their concatenation \(AB\) is also a RBS.
Note: The empty sequence is not considered a RBS.
You are required to decide whether it is possible to construct such a partition so that at least m out of the 2*m arrays are Beautiful. If a valid partition exists, output one valid construction; otherwise, output NO
.
inputFormat
The first line contains two integers n and m (1 ≤ n ≤ 105, 1 ≤ m ≤ n/2).
The second line contains a string s of length n consisting only of characters '(' and ')'.
outputFormat
If a valid partition exists, output YES
on the first line. Then output 2*m lines. The i-th of these lines should begin with an integer k (the number of indices in array \(p_i\)), followed by k space-separated integers in strictly increasing order representing the indices in \(p_i\).
If no valid partition exists, output NO
.
sample
4 1
()()
YES
2 1 2
2 3 4
</p>