#P10994. 【MX-J3-T1】 Seats
【MX-J3-T1】 Seats
Background
Original link: https://oier.team/problems/J3B.
Problem Description
Note: All array indices in this statement start from .
There is a lecture with students and teachers signed up. The organizer has prepared some seats, and uses a string to represent the type of each seat. For the -th seat from left to right, means it is a teacher seat, and means it is a student seat.
Teacher seats can only be used by teachers, student seats can only be used by students, and each seat can be occupied by at most one person.
However, with the current arrangement, not all teachers and students can get a seat. So the organizer plans to make some changes. One modification can choose a teacher seat and change it into a student seat, or choose a student seat and change it into a teacher seat.
Determine the minimum number of modifications needed so that both teachers and students can all have seats. In particular, if no matter how you modify it, it is impossible for everyone to have a seat, output .
Input Format
The first line contains two positive integers , representing the number of students and teachers.
The second line contains a string representing the type of each seat prepared by the organizer.
Output Format
Output one line with one integer, the answer as described in the statement.
3 4
STTSTTTT
1
100 100
SSTT
-1
33 24
SSTTTTSSTSTSTSSTSTSTTTSSSTSSTTSTSSTTTTSTSTTTTSSTTTTTSTTTTSTSSSSS
4
Hint
Sample Explanation #1
There are students and teachers signed up. If you change the -nd seat into a student seat, then the students can sit in seats , and the teachers can sit in any four of seats .
Clearly, if you do not adjust the seats, there are not enough seats for students.
Sample Explanation #2
No matter how you modify it, it is obviously impossible for students and teachers to sit in only seats, so output .
Constraints
This problem has test points, each worth points. Let be the number of characters in the string .
| Test Point ID | Special Property | |
|---|---|---|
All characters in are S |
||
All characters in are T |
||
| No special property | ||
For all testdata, it is guaranteed that , and the string contains only uppercase letters S or T.
Translated by ChatGPT 5