Husk, 2121 19 bytes
↑⁰↑mȯ!²Tm₁N
¢+R⁰0…→Σ←⁰Σ⁰⁰¢§+`R0§…ȯ→Σ←ΣN
Takes arguments as n (01-indexed), then x.
NotSaved 2 bytes thanks to BMO, but still not as short as BMO's answer, but my.
My first attempt at using Husk.
Try it online!Try it online!