AlgoUniversity
  • Go Back
Discussion
Maximum Sum Matrix :

Author

Yash Sahijwani

Difficulty Level : Medium

Submissions : 346

Asked In : Uber

Marks :10

: 6 | : 0

You are given a matrix of positive integers. You need to find the maximum possible sum of 2 integers from the matrix, such that the 2 integers are neither in the same row nor in the same column.

Input

The first line of input consists of two space separated integers, $$$n$$$ and $$$m$$$ $$$-$$$ which denote that the matrix has $$$n$$$ rows and $$$m$$$ columns. Then each of the next $$$n$$$ lines consist of $$$m$$$ space separated integers, where the $$$j_{th}$$$ number in the $$$i_{th}$$$ line denotes $$$a[i][j]$$$. $$$(1 \leq n*m \leq 10^6)$$$ $$$(1 \leq a[i][j] \leq 10^9)$$$

Output

The output should consist of a single integer - the maximum sum obtained.

Example

Input
2 2
5 19
4 13
Output
23

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.