Cinema Academy
InterviewTime limit1sMemory limit1024 MB
Choose two different films to win best directing and best screenplay so that the total delight, where each film contributes one of three values depending on its outcome, is maximized.
- Level
Medium5 of 10
- Topics
- Greedy, Array, Implementation, Sorting
- Solved
- No attempts yet
Problem
The best films of 2014 reached the final of the Cinema Academy contest. The contest awards films in two categories: best directing and best screenplay. By the rules, exactly one film must be awarded in each category, and the films awarded in the two categories must be different.
Through numerous surveys of viewers and film critics, data was collected showing the level of delight that a win by each film in each category would cause. Thorough journalists did not stop there and also determined the level of delight if a given film wins in neither category.
Write a program that uses the survey results to determine the greatest total level of delight that can be achieved by choosing the films to award in the given categories.
Input
The first line of the input file contains an integer , the number of films competing in the final of the Cinema Academy contest. The next lines contain three integers each, , , : the level of delight if the -th film wins in neither category, the level of delight if this film wins best directing, and the level of delight if this film wins best screenplay.
Output
The first line of the output file must contain a single number: the greatest possible total level of delight. The second line must contain two integers: the numbers of the winning films in best directing and best screenplay, respectively. Films are numbered with the natural numbers from to . If there are several optimal ways to choose the awarded films, you may output any of them.
Constraints
Hint
In the example given, the greatest total level of delight is .