use heap instead of sort