Coins
Time limit2sMemory limit512 MB
Maintain the probability that the number of heads among N coins is odd, under M point updates to individual coin probabilities, and report which outcome is more likely after each update.
- Level
Medium7 of 10
- Topics
- Math, Probability, Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
There are coins with possibly different heads probabilities. Toss all coins. You survive when the number of heads is odd, and you die when it is even.
An initial state is given, followed by updates. Each update specifies a coin index and its new heads probability. Compare the survival probability against the death probability in each of the states, from the initial state with updates to the final state with updates.
Input
The first line contains and , where and . The second line contains real numbers. The -th number is the heads probability of coin . Each of the following lines contains a coin index and its new probability.
Every probability is at least and at most , written with up to digits after the decimal point.
Output
Print lines. Line holds the answer for the state after updates.
Print "ALIVE" when survival is more likely and "DEAD" when death is more likely. Print "SAME" when the two probabilities are equal.
Hint
With heads probabilities , , and , survival has probability and death has probability . Survival is more likely.