Sort tasks by deadline in matrix