Rover.com Interview Question

How would you write this objective function?