Editorial
Increasing by one adds . Because is non-increasing, an optimum never needs to take a lower value in a column without taking every value above it. Hence the answer is the sum of the largest values among all pair sums .
After sorting , the number of pair sums at least an integer can be counted in using binary search for every . Find the largest for which this count is at least . Sum every pair strictly greater than , then add for the remaining pairs. The answer may exceed 64-bit range, so a 128-bit integer is required.