Sunshine
TCO19 SRM 761 · 2019-06-21 · by misof
Problem Statement
Peter was recently on a holiday. The holiday lasted for totalDays days. Peter remembers that exactly rainyDays of them were rainy and the others were sunny.
We will use the letters 'R' and 'S' to represent rainy and sunny days. For example, the string "SSSRSS" represents a 6-day holiday during which day 4 was rainy and the other five days were sunny.
We say that the beauty of the holiday is the maximal number of consecutive sunny days during the holiday. For example, the beauty of "SSSRSS" is 3 and the beauty of "RRR" is 0.
Given totalDays and rainyDays, determine the smallest possible beauty of Peter's holiday. Then, construct and return one string that represents such a holiday.
(The returned string should have the correct number of days, it should have the correct number of rainy days, and its beauty must be the smallest among all such strings. If there are multiple optimal solutions, you may return any one of them.)
Constraints
- totalDays will be between 1 and 2000, inclusive.
- rainyDays will be between 0 and totalDays, inclusive.
6 1 Returns: "SSSRSS"
The example from the problem statement. Another correct answer is "SSRSSS".
3 3 Returns: "RRR"
Another example from the problem statement. This is the only correct answer.
12 8 Returns: "RRSRRSRSRRRS"
8 2 Returns: "SSRSSRSS"
5 0 Returns: "SSSSS"
Submissions are judged against all 114 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Sunshine with a public method string weatherReport(int totalDays, int rainyDays) · 114 test cases · 2 s / 256 MB per case