The Careful Average
City Hall keeps getting neighborhood reports - noise levels, air quality, you name it. But a single report can be misleading. You are asked to help them, but only trust a neighborhood’s average if there are enough reports. Otherwise, fall back to the citywide average.
The first line of the input contains a single integer n
, the number of (neighborhood, value)
reports.
The next n
lines each contain a neighborhood name (no spaces) and an integer value (the number of reports).
The following line contains an integer m
, the minimum number of reports required to trust a neighborhood’s own average.
The next line contains an integer q
, the number of neighborhoods to predict for.
The next q
lines contain a neighborhood name to query.
For each queried neighborhood:
If it has at least
m
reports, print its mean value.Otherwise, print the global mean across all
n
reports.
Input | Output |
---|---|
6 | 7 |
6 | 7 |
5 | 6 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB