A film studio keeps two records: how many years of experience each crew member has, and which productions each crew member is currently assigned to (a crew member may be assigned to several productions at once, and a production may have many crew members). For every production that has at least one assigned crew member, compute the average years of experience across its assigned crew, rounded to exactly two decimal places.
e and m: the number of crew members and the number of assignment records.e lines contains two integers employeeId and experienceYears, giving one crew member's id (unique across all crew members) and years of experience.m lines contains two integers projectId and employeeId, meaning that crew member employeeId is assigned to production projectId. Every employeeId referenced here is one of the e crew members listed above, and no (projectId, employeeId) pair repeats.Print one line per distinct projectId that appears among the assignment records, in strictly increasing order of projectId. Each line contains the projectId, a single space, and the average experience of its assigned crew formatted with exactly two digits after the decimal point.
Example 1
Input
3 3 1 5 2 3 3 8 10 1 10 2 20 3
Expected
10 4.00 20 8.00
Explanation
Project 10's crew is employees 1 and 2, with experience 5 and 3 years, averaging (5+3)/2 = 4.00. Project 20's only crew member is employee 3, with 8 years, averaging 8.00.
Example 2
Input
3 3 1 1 2 2 3 2 5 1 5 2 5 3
Expected
5 1.67
Explanation
All three employees (experience 1, 2, and 2 years) are assigned to project 5, so its average is (1+2+2)/3 = 1.6666..., which rounds to 1.67.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →