Comments

Very fast one line O(n log n) solution to problem C in Dyalog APL.

⎕IO←0 ⋄ {n l r←⎕ ⋄ ⎕←(r,l-1) -.{+/0⌈(⍳≢⍵)-⍨⍵⍸⍺-⍵} ⊂{⍵[⍋⍵]}⎕}¨⍳⎕

Try it online

This would be a great language to add.