Let's Split Up!
InterviewTime limit1sMemory limit1024 MB
Split n people into two groups, each with one leader and one room, to minimize the largest danger a*k*b, and print the minimum with the assignment.
- Level
Medium5 of 10
- Topics
- Binary search, Math, Brute force
- Solved
- No attempts yet
Problem
As every horror movie shows, sooner or later someone comes up with the brilliant idea of splitting up to explore a creepy, suspicious place in small groups.
This time a party of people is exploring an abandoned hut in a dark forest, and they decide to split into two groups. The party has two leaders with recklessness and . Two rooms are available for the search, with suspicion levels and .
Each group must have exactly one of the two leaders. If the group of the -th leader has people (not counting the leader) and explores room , the danger of that search is .
You want to help them minimize the danger of this plan. Split the non-leaders into two groups (one group may be empty), and assign each group a leader and a room so that the larger of the two dangers is as small as possible.
Input
The first line contains one integer , the number of people not counting the two leaders ().
The second line contains two integers and , the recklessness levels of the two leaders ().
The third line contains two integers and , the suspicion levels of the rooms ().
Output
Print one integer, the smallest possible value of the larger of the two dangers.
On the next line, print the number of the room that the first leader's group explores and the number of people in that group (not counting the leader), separated by a space. On the last line, print the same information for the second leader's group.
If there are several answers, print any of them.