Given sum of each row and each column in a matrix check whether a binary matrix can be created ?
Input :
The first row of input contains two numbers 1≤m,n≤100000000, the number of rows and columns of the matrix. The next row contains m numbers 0≤ri≤n – the sum of each row in the matrix. The third row contains n numbers 0≤cj≤m – the sum of each column in the matrix.
Output:
Output “YES” if there exists an m-by-n matrix A, with each element either being 0 or 1. Else "NO".
I trid the solution posted in Finding if binary matrix exists given the row and column sums
Above Solution works fine for small inputs but when input is of the order of 1 billion then the testing plaforms like codility times out.I need a solution that is better than o(m*n).Can someone please help here?