Distributing parliament seats
Python 2, 220 bytes



def d(l,n,a=0,b=1.):s=sum(x//b for x in l);return s-n and d(l,n,*[a,b,(a+b)/2,b*2][s&gt;n::2])or b
def f(l,b,n):l=[[x*(x&gt;=b*sum(sum(l,[])))for x in r]for r in l];return[[v//d(x,sum(x)//d(map(sum,l),n))for v in x]for x in l]


Try it online!

Basically just a golf of the reference implementation...