Uiua
It took me a while to work out the merging of ranges, but I'm very pleased with the solution.
D β "3-5\n10-14\n16-20\n12-18\n\n1\n5\n8\n11\n17\n32"
# D β &fras"2025day05.txt" # drop your input file on this pane and uncomment this line to test against your own data.
Parse β β©(βββΈβ+@0β‘10)Β°β‘βββ‘Β¬βΈβ¦·"\n\n"
Merge β ⨬(
⨬(β # -> distinct, keep both.
| ββ’β(β₯β©β£) # -> overlap, merge them.
)β‘(β€ββ£β’)
| ββ # -> inside, ignore it.
)β‘(β€β©β£)
Ranges β βββ₯ββ£(MergeβΒ°β)β‘β
β§»βββ1ββ―β_2 # Merge pairs of ranges.
Pβ β /+β‘β(/β₯β‘β(β§βββ₯β€Β°β))
Pβ β /+β‘(+1/-)ββ
βPβ Pβ Ranges Parse D