Problem link: https://www.hackerearth.com/code-monk-sorting/algorithm/monk-in-the-grass-fields/
My code: https://www.hackerearth.com/submission/2962880/
My logic:
1) Find sum of elements in each row and store in an array called rowsum.
2) Find sum of elements in each column and store in an array called colsum.
3) Sort rowsum and colsum
4) Choose the row sum or column sum with the least value. Let's say it's a row which has the least value. Increase that particular row sum by n, and increment all colsum values by 1. Can happen vice versa.
5) Sort. Repeat.
Might not be the most efficient, but it seems to be wrong as such. I don't really get the idea described in the editorial in the problem link either. So could someone please clarify why my logic is wrong and in what angle I should approach the problem instead (just a hint)?