Scoring in Log-Space
Halyard Mail's filter keeps falling over on long messages. Every label's score reaches exactly zero and the labels all tie, because each feature drives the running value further down and no computer can hold a number that small. The team's answer is to stop tracking the score itself and track its logarithm instead -- a scale on which numbers that small stay perfectly readable. Everything now arrives already converted: the label's prior comes in as its logarithm, and so does every feature's likelihood.
Task: Print the logarithm of this label's score.
Input
The first line holds the logarithm of the label's prior. The second line holds one integer n, the number of features. The third line holds n numbers separated by single spaces, each the logarithm of one feature's likelihood.
Output
One line holding the logarithm of the score, rounded to 4 decimal places. Every number arriving is the logarithm of a probability, so none of them is above zero and the answer will not be either.
Example:
Input:
-1.0
2
-0.5 -0.3
Output:
-1.8000
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in