This is correct solution.Some optimization required so that I don't have 2 read entire table whenever I check fr constraints.I can hav 1 extra row or col 2 store d sum of values