Format a Table
Time limit5sMemory limit64 MB
Given a 3x3 table of cell text lengths and a total width w, split w into three column widths that minimize the sum of the three row heights.
- Level
Hard8 of 10
- Topics
- Brute force, Math, Binary search
- Solved
- No attempts yet
Problem
Little Vadim has a homework assignment at school. He has to describe the characters of a famous literary work. Vadim finished the homework and wrote a report as a spreadsheet in his favorite text editor.
The spreadsheet is a table of size . The text in the cell at row and column has length . The total width of the table is characters. The editor lets you change the width of each column in any way. If the column widths are , , and , then . The height of row is , and the total height of the table is .
Vadim noticed that changing the column widths changes the table height in an unpredictable way. He is a perfectionist, so he wants the total height to be as small as possible. Help Vadim find the optimal solution.
Input
The first line contains an integer ().
Each of the next three lines contains three integers. The -th number in the -th of these lines is ().
Output
In the first line, output the integer , the minimum possible height of the whole table.
In the second line, output three integers , , and , the column widths that give the optimal solution.
If there are several solutions, output any of them.
Hint
The following table matches the data from the first sample.