ll@N,@++M,@(C,D)[N],A[M]{};rsortA(N,C,D);rep[C,i](c,N)REP(j,M-c)A[j/2]>?=A[j+c]+D[i];wt(max(A(M)));