Score : $400$ points
Takahashi will toss a coin $N$ times. He also has a counter, which initially shows $0$.
Depending on the result of the $i$-th coin toss, the following happens:
Additionally, there are $M$ kinds of streak bonuses. The $i$-th kind of streak bonus awards $Y_i$ yen each time the counter shows $C_i$.
Find the maximum amount of money that Takahashi can receive.
Input is given from Standard Input in the following format:
$N$ $M$ $X_1$ $X_2$ $\ldots$ $X_N$ $C_1$ $Y_1$ $C_2$ $Y_2$ $\vdots$ $C_M$ $Y_M$
Print the maximum amount of money that Takahashi can receive, as an integer.
6 3 2 7 1 8 2 8 2 10 3 1 5 5
48
If he gets head, head, tail, head, head, head, in this order, the following amounts of money are awarded.
In this case, Takahashi receives $2+(7+10)+0+8+(2+10)+(8+1)=48$ yen in total, which is the maximum possible.
Note that streak bonuses are awarded any number of times each time the counter shows $C_i$.
As a side note, if he gets head in all $6$ coin tosses, he only receives $2+(7+10)+(1+1)+8+(2+5)+8=44$ yen, which is not the maximum.
3 2 1000000000 1000000000 1000000000 1 1000000000 3 1000000000
5000000000
Note that the answer may not fit into a $32$-bit integer type.