Each row of matrix (N x M+3) will store the ratings at the end of M months, month of highest rating achieved, best ranking achieved, month of best ranking.
For each row, find the max rating of each participant and store in (M+1)th column.
Sort each month (column) row wise in descending order of rating. Find the ranks of each participant at the end of first month and store in (M+2)th column.
For subsequent months (column) after sorting row wise find ranks of each participant (row) and replace it with the rank in (M+2)th column only if the current rank is better (less). Then store that month in (M+3)th column.
This solution is not working except the example test cases of the question -