Sogang Muscle Man
InterviewTime limit1sMemory limit1024 MB
Pair up N machines into floor(N/2) pairs plus possibly one leftover so the largest pair sum is minimized, and report that smallest possible maximum.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Two pointers, Binary search
- Solved
- No attempts yet
Problem
After watching Ronnie Coleman videos, Hyangbin decided to become a bodybuilder and went to Sogang Health Club for a PT consultation. He chose Sogang Health Club because members can pick which exercise machines they use during a PT session. But Sogang Health Club is always crowded, so in one PT session he can choose at most two machines.
Hyangbin wants to use each of the machines in the gym exactly once, so he planned to pick machines he had not used before in every PT session. To save money, he decided to use two machines per PT session whenever possible. For example, if the gym has machines in total, PT sessions use all of them. With machines he still has PT sessions, but in the last session he uses only one machine.
Choosing the machines put Hyangbin in a bind. Each machine causes a different amount of muscle loss. Some machines give little stimulation, so muscle loss is small, while others give strong stimulation, so muscle loss is large. Hyangbin fears muscle loss more than death, so he wants the muscle loss of any single PT session to stay at or below . Find the minimum possible value of . When a PT session uses two machines, the muscle loss of that session is the sum of the muscle losses of the two machines.
Input
The first line gives the integer , the number of exercise machines in Sogang Health Club. ()
The second line gives the integers , the muscle loss of each machine. ()
Output
Print the minimum value of .