Dormvival Games
Time limit0.5sMemory limit128 MB
Simulate M weeks of adjacent room swaps driven by weekly merit and demerit scores, tracking how often the gap between Hong and Cho stays within B.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation, Array
- Solved
- No attempts yet
Problem
The dormitory of Seoul S Science High School is famous for its very unusual system. The dormitory has many rooms, and each room has a number: the smaller the number, the better the room. The dormitory administration gives students merit points and demerit points, but unlike the system of some science high schools, there is no expulsion policy based on accumulated demerit points. So each week the dormitory administration reassigns students' rooms according to each student's merit and demerit points. The best rooms, close to room 1, are in very good condition and students want them, while the worst rooms, close to the last room, are in terrible condition and students try to avoid them.
The dormitory administration first assigned rooms based on student ID numbers. Students are given student IDs from 1 to N, and in the first week they enter the rooms according to those numbers. Hong, whose ID is 1, and his close friend Cho were assigned in the first week to room 1 and room A, respectively. Hong wants to be with Cho, and if the difference between the two students' room numbers is at most B, Hong feels happy that week. Students live in the dormitory for the given M weeks, and in the last week no merit or demerit points are given. That is, merit and demerit points are recorded only for M-1 weeks.
Find the total number of weeks during the M weeks in which Hong feels happy, and find the maximum number of consecutive weeks in which Hong feels happy.
-
Room swaps
- A swap of two rooms means exchanging the occupants of the two rooms.
- Starting from the best room and going to the worst room, only two rooms adjacent in rank are swapped. That is, first rooms 1 and 2 are checked, then rooms 2 and 3, and finally the merit/demerit points of rooms N-1 and N are checked.
- The merit and demerit points used as the criterion for a room swap are checked only from the week before the swap. That is, merit and demerit points are reset every week.
-
Conditions for a room swap. The conditions for a swap of two rooms to occur are as follows. Here, the score is merit points minus demerit points.
- If both students' scores are at least 0, the two rooms are swapped when the score of the student in the worse room is at least 2 points higher than the score of the student in the better room.
- If the student in the better room has a score of at least 0 and the student in the worse room has a negative score, the rooms are not swapped.
- If the student in the worse room has a score of at least 0 and the student in the better room has a negative score, the rooms are swapped.
- If both students' scores are negative, the two rooms are swapped when the score of the student in the worse room is at least 4 points higher than the score of the student in the better room.
- If the rooms are swapped, the person who moved to a better room receives -2 points and the person who moved to a worse room receives +2 points, which prevents sharp changes in room number.
Input
The first line gives, in order and separated by single spaces, the total number of students N (10 ≤ N ≤ 100), Cho's room number A (1 < A ≤ N), the happy value B (1 ≤ B ≤ 50), and the length of the dormitory stay in weeks M (1 ≤ M ≤ 50).
From the second line, M-1 lines give the merit and demerit point information for each week. For each week, in order of student ID, N merit points are given on one line, and N demerit points are given on the next line. Merit and demerit points are integers greater than or equal to 0 and less than 100.
Output
On the first line, print the number of weeks in which Hong felt happy and the maximum length of a run of consecutive happy weeks, separated by a space. If Hong does not feel happy in any week, the maximum length of a run of consecutive happy weeks is defined as 0.