solving maximum damage