Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the function below: vector bestPros(vector > pros, int k) { } int main() When a Thumbtack user creates a new project, we recommend the

image text in transcribed

image text in transcribed

Complete the function below:

vector bestPros(vector> pros, int k) {

}

int main()

When a Thumbtack user creates a new project, we recommend the best Pros for the job based on a metric called the Pro Matching Score (PMS). This score is calculated using two factors the distance the Pro would have to travel to the job, and the Pro's average rating. More specifically, PMS is defined as (max_distance - distance) + rating where max_distances the maximal distance that any Pro has from the given user. Naturally, a higher PMS means the Pro is a better match for the project You have an array that represents the Pros who are available to complete a new project for a user where each element of the array is a distance, rating] tuple distance is the distance of the Pro from the user's project location, and rating is their overal rating Given the array pros for a specific project determine the kPros who are best suited to complete it based on their Pro Matching Score. Return a list of the indices (0-based) at which these Pros appeared in the original pros array, sorted by their PMS score. In the case of a PMS tie the Pro with the smaller index goes first Example For pros - [(5, 4], [4, 3), (6, 5), (3, 5]] and k = 2, the output should be bestPros(pros, k) = [3, 1]. The PMSs of the Pros are: oth pro: (6 - 5) * 4 - 4 1st pro: (6 - 4) * 3 - 6 2nd pro: (6 - 6) * 5 - B; 3rd pro: (6 - 3) * 5 - 15. The output is [3, 1] since the Pros at indices 1 and 3 have the highest scores. Since pro[3] has a higher PMS than pro[1]. index 3 appears first in the array Input/Output [execution time limit] 4 seconds (is) [input] array array.integer pros An array of Pros. For each valid pros[1] contains two elements: pros(] ] is the distance of the 4th Pro from the user's location and pros (1) is the Pro's overall rating Guaranteed constraints: 1 s pros.lengths 184 1 spros[1]. Length - 2 1 spros[i][j] = 102 [input) integer k The number of Pros who should be recommended to complete the user's project. Guaranteed constraints: 1 sk s pros. Length (output) array.integer The indices of the k best Pros to complete the user's project from the original pros array, sorted by their Pro Matching Score. In the case of a PMS tie the Pro with the smaller index goes first. If there are fewer than k suitable Pros, return all of them

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is Constitution, Political System and Public Policy? In India

Answered: 1 week ago

Question

What is Environment and Ecology? Explain with examples

Answered: 1 week ago