Magnus Ditlev timed his race perfectly to claim triathlon T100 victory in Miami, as Alistair Brownlee faded after holding the lead.