Rank Promotion
Time limit3sMemory limit1024 MB
Given n quiz results as Y or N, compute the final rank when a rank rises after any window of at least c quizzes with correct ratio at least p/q, starting from the current rank.
- Level
Hard8 of 10
- Topics
- Prefix sum, Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
Quiz Solver is a popular online computer game. Each time a player opens the mobile app, a new quiz appears. The player submits an answer, which is judged correct or incorrect and recorded in the database. When a player shows high accuracy over many quizzes, the player's rank is promoted.
Player ranks are non-negative integers, and every player starts at rank . Promotion is defined by an integer and a rational number . After the -th quiz, the player's rank increases by one if there is an integer such that:
- .
- The player was already at the current rank before the -th quiz started.
- The ratio of correct answers from the -th through the -th quiz is at least .
Otherwise, the rank stays the same.
One day, the administrator of Quiz Solver found that the rank data of the players was lost in a database failure. The log of quiz solving records was completely intact. Recompute each player's rank from that player's solving records.
Input
The input is a single test case in this format.
The first line has four integers with , , and . is the number of quizzes answered by one player, and , , have the meanings given in the problem statement. Each is Y if the answer to the -th quiz was correct, or N if it was incorrect.
Output
Output the player's final rank after the -th quiz on one line.
Hint
In Sample Input 1, the player is promoted to rank 1 after the fourth quiz, because the correct ratio 3/4 is higher than . No promotion happens at the third quiz, since only three quizzes have been answered, fewer than . After the eleventh quiz, the player is promoted to rank 2.

Figure B.1. Rank promotion timings for Sample Input 1