#P10994. Seating Arrangement Adjustment
Seating Arrangement Adjustment
Seating Arrangement Adjustment
Given a lecture with a students and b teachers registered, the organizer has prepared a row of seats. The seating arrangement is described by a string \(s\) of length \(n\) where for the \(i^{th}\) seat (indexed from \(1\)), \(s_i = \texttt{T}\) indicates a teacher seat and \(s_i = \texttt{S}\) indicates a student seat.
A teacher seat can only be occupied by a teacher and a student seat only by a student, with each seat occupied by at most one person.
Currently, not every teacher or student may have a seat. To remedy this, the organizer is allowed to perform the following operation any number of times: choose one seat and flip its type (i.e. change a teacher seat to a student seat or vice versa).
Your task is to determine the minimum number of modifications needed so that there are at least \(b\) teacher seats and at least \(a\) student seats available. If it is impossible to seat everyone, output \(-1\).
Note: All array indices are \(1\)-indexed.
inputFormat
The first line contains two integers \(a\) and \(b\) representing the number of students and teachers, respectively.
The second line contains a string \(s\) of length \(n\), where \(s_i\) is either T
or S
, representing the type of the \(i^{th}\) seat.
Remember, the indices of the seats start from 1
.
outputFormat
Output a single integer: the minimum number of modifications required to ensure there are at least \(b\) teacher seats and at least \(a\) student seats. If it is impossible, output \(-1\).
sample
2 3
TSSST
1