Room Temperature
InterviewTime limit2sMemory limit1024 MB
Choose an integer room temperature that minimizes the worst officer's distance to their achievable temperatures A_i - kT, with k at least 0.
- Level
Medium6 of 10
- Topics
- Binary search, Sorting, Math
- Solved
- No attempts yet
Problem
President K is adjusting the room temperature of the officers' room. He wants the officers to be as comfortable as possible.
There are officers in the room, numbered from 1 to . When officer () is not wearing a jacket, the appropriate temperature for that officer is degrees. Each jacket the officer wears lowers the appropriate temperature by degrees. If officer is wearing jackets, the appropriate temperature is degrees.
When the room temperature is degrees and an officer's appropriate temperature is degrees, that officer's discomfort index is , where is the absolute value of . Each officer wears between 0 and as many jackets as needed to minimize their discomfort index for the given room temperature.
President K defines the room's unpleasantness as the maximum discomfort index among all officers. He sets the room temperature to minimize the room's unpleasantness. The room temperature must be an integer.
Given the officers' information and their appropriate temperatures, write a program that computes the minimum possible room's unpleasantness.
Input
The first line contains and . The second line contains , separated by spaces.
Output
Print one line containing the minimum room's unpleasantness.
Constraints
- for all
- All given values are integers.