Karl-Anthony Towns scored 39 points and Landry Shamet added a career-high 36 points off the bench as the New York Knicks beat the Miami Heat 140-130 in an NBA Cup game on Friday night.