sub max{$_[$_[0]<$_[1]]} ($n,$m,$k)=glob<>; $b{0,300}=$k; for(<>){ $_+=0; for$i(0..$m-1){ for$j($_..300){ $b{$i,$_}=max($b{$i,$_},$b{$i,$j}); } } %c=%b; for$i(0..$m-1){ for$j(100..$_){ $k=max($k,$b{$i+1,300}=max($b{$i+1,300},int($c{$i,$j}/$j)*$_+$c{$i,$j}%$j)); } } } print $k;