A delivery app suggests a ranked list of routes to its drivers for every order, and logs, for each completed order, which rank the chosen route held in that list and what star rating (1 to 5) the customer gave the delivery. The app wants two numbers for every delivery zone: an efficiency index that rewards zones where highly-rated deliveries came from routes suggested near the top of the list, and a complaint rate measuring how often customers were unhappy.
For a zone, the efficiency index is the average, over all of that zone's orders, of rating / rank (a route ranked 1st that earned a 5-star rating contributes 5.0; the same rating for a route ranked 5th contributes only 1.0). The complaint rate is the percentage of that zone's orders whose rating was strictly less than 3.
The first line contains a single integer n, the number of completed-order records.
Each of the next n lines contains three space-separated values zone_name rank rating, where zone_name is a string of 1 to 20 lowercase English letters and digits, rank is the position (starting at 1) of the suggested route that was used, and rating is the customer's star rating for that order.
For every distinct zone_name, sorted lexicographically ascending, print one line containing zone_name, its efficiency index, and its complaint rate (as a percentage), each rounded to exactly two decimal places and separated by single spaces.
Example 1
Input
5 dog 1 5 dog 2 5 dog 3 5 cat 2 1 cat 5 1
Expected
cat 0.35 100.00 dog 3.06 0.00
Explanation
Zone "dog" has three orders with rating/rank values 5/1=5.0, 5/2=2.5, and 5/3≈1.6667, averaging to about 3.0556, which rounds to 3.06; none of its ratings are below 3, so its complaint rate is 0.00. Zone "cat" has two orders with rating/rank values 1/2=0.5 and 1/5=0.2, averaging to 0.35; both ratings are 1, which is below 3, so its complaint rate is 100.00. Zones are printed in lexicographic order, so "cat" comes before "dog".
Example 2
Input
4 alpha 1 1 alpha 2 4 alpha 3 5 beta 10 3
Expected
alpha 1.56 33.33 beta 0.30 0.00
Explanation
Zone "alpha" has ratios 1/1=1.0, 4/2=2.0, and 5/3≈1.6667, averaging to about 1.5556, which rounds to 1.56; only its first order (rating 1) is below 3, out of 3 orders, giving a complaint rate of 33.33. Zone "beta" has a single order with ratio 3/10=0.3, so its efficiency index is 0.30, and its rating of 3 is not below 3, so its complaint rate is 0.00.
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 →