Editorial
Consider each column independently.
For two sequences , the value is the maximum of over all columns . For a fixed column , the largest possible sum is obtained by choosing the two largest values in that column from two distinct sequences.
While reading the input, maintain the largest and second largest values for each column, together with the indices of the sequences where they appear.
After reading the input, check every column . The pair corresponding to the largest sum of the two largest values in a column is an optimal answer.
For correctness, fix any pair and any column . The value cannot exceed the sum of the two largest values in column . Hence no pair can achieve a value larger than the best candidate we check. Conversely, the two sequences chosen from the best column actually achieve that candidate value, so the answer is optimal.
The time complexity is , and the memory complexity is .