#C8635. Maximum Score Difference in Partitioned Rooms
Maximum Score Difference in Partitioned Rooms
Maximum Score Difference in Partitioned Rooms
You are given N
participants, each having a score, and K
rooms. The participants are first sorted by their scores in non-decreasing order. They are then assigned to the rooms in contiguous blocks such that each room gets \lceil N/K \rceil
participants (except possibly the last room which might have fewer participants). The task is to calculate the maximum possible score difference within any room, where the score difference of a room is defined as the difference between the maximum and minimum scores in that room.
Note: The ceiling function \(\lceil N/K \rceil\) is computed as \(\frac{N+K-1}{K}\) in integer arithmetic.
inputFormat
The input is given via STDIN as follows:
- The first line contains two integers
N
andK
, whereN
is the number of participants andK
is the number of rooms. - The second line contains
N
space-separated integers representing the scores of the participants.
outputFormat
Output a single integer to STDOUT which is the maximum score difference across all rooms.
## sample6 3
100 200 300 450 500 750
250
</p>