#K44042. Valid Playlist Arrangement
Valid Playlist Arrangement
Valid Playlist Arrangement
You are given a list of songs along with their durations and types. Each song is either fast-paced ('F') or slow-paced ('S'). Your task is to determine if it is possible to arrange the songs into a playlist such that no more than \(k\) consecutive songs of the same type appear.
The input begins with an integer \(T\) indicating the number of test cases. For each test case, the first line contains two integers \(n\) and \(k\) — the number of songs and the maximum allowed consecutive songs of the same type. The second line contains \(n\) integers representing the durations of the songs (which are provided for context but do not affect the solution). The third line contains \(n\) characters (each either 'F' or 'S') indicating the type of each song.
Your program should output POSSIBLE
if a valid playlist arrangement exists and IMPOSSIBLE
otherwise. Note that the durations are included in the input for completeness but play no role in determining the validity of the arrangement.
inputFormat
The first line contains an integer \(T\) denoting the number of test cases. Each test case consists of the following three lines:
- The first line contains two space-separated integers \(n\) (the number of songs) and \(k\) (the maximum allowed consecutive songs of the same type).
- The second line contains \(n\) space-separated integers representing the durations of each song.
- The third line contains \(n\) space-separated characters where each character is either 'F' (fast-paced) or 'S' (slow-paced), representing the type of each song.
outputFormat
For each test case, output a single line containing either POSSIBLE
if it is possible to arrange the playlist under the given constraints, or IMPOSSIBLE
if it is not.
5
3 2
4 5 3
F S F
4 1
2 3 5 6
F F S S
1 1
5
F
7 2
1 2 3 4 5 6 7
F F S S S F F
2 1
1 2
S F
POSSIBLE
IMPOSSIBLE
POSSIBLE
IMPOSSIBLE
POSSIBLE
</p>