Do the example you are saying, although if it is a task, you should do it yourself.
The only thing that is necessary is to make the correct distribution of the initial percentages, the rest works well.
Html
<h1>Porcentaje
<input id="numero"/>
<input type="button" value="Enviar" onclick="calcularPorcentaje()"/>
</h1>
<div id="salida"></div>
javascript
var cantidadMunicipios=37;
var municipios=[];
for (var i=0;i<cantidadMunicipios;i++){
// Creando número aleatorios.
// este valor debe ajustarse todos los municipios para que el total de los 37 sea 100%, porque de otro modo se pasaría del presupuesto.
var porcentaje=Math.round(Math.random()*30)+1;
var barrios=[Math.round(Math.random()*49)+1,Math.round(Math.random()*49)+1];
//incrusta un array dentro de otro, así crea un array bidimensional
// lo mismo sucede con la variable Barrios, ese sería el tercer nivel del array
municipios.push(["Municipio "+(i+1),porcentaje,barrios]);
}
var calcularPorcentaje=function(){
var num=document.getElementById('numero').value;
document.getElementById('salida').innerHTML = "";
for (var i=0;i<cantidadMunicipios;i++){
var tempElement = document.createElement('div');
var newDiv = document.createElement("div");
var p1 = document.createElement('p');
var valorMunicipio=(num*municipios[i][1])/100;
p1.innerHTML = "<b>"+municipios[i][0]+":</b> %"+municipios[i][1]+" => "+valorMunicipio;
document.getElementById('salida').appendChild(p1);
for (var j=0;j<municipios[i][2].length;j++){
var p = document.createElement('div');
p.innerHTML = "<div style='margin-left:25px'> Barrio"+(j+1)+": %"+municipios[i][2][j]+" => "+(valorMunicipio*municipios[i][2][j])/100+"</div>"
document.getElementById('salida').appendChild(p);
}
}
}
functional example