The following table lists how many points a player gets depending on how far away the actual button press is from the expected button press, in milliseconds:
Time Difference (ms) |
Points |
$[0, 15]$ |
7 |
$(15, 23]$ |
6 |
$(23, 43]$ |
4 |
$(43, 102]$ |
2 |
Wildly inaccurate presses with a difference of $103$ milliseconds or more score no points.
During gameplay, the player presses the button some number of times. To score the game, match each actual button press with at most one expected button press, with the following restriction: if one actual button press happens before another actual button press and both button presses are matched with expected button presses, then the expected button press for the first must be strictly before the expected button press for the second.
Because you are generous, you decide to compute the matching that maximizes the number of points the player earns. Compute the final score of the round of Rhythm Flow under this matching.
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 2\, 000$), where $n$ is the number of expected button presses and $m$ is the number of actual button presses.
Each of the next $n$ lines contains a single integer $e$ ($1 \le e \le 10^9$). These are the times of the expected button presses in milliseconds from the start of the round. It is guaranteed that these values are unique and in sorted order.
Each of the next $m$ lines contains a single integer $a$ ($1 \le a \le 10^9$). These are the times of the actual button presses in milliseconds from the start of the round. It is guaranteed that these values are unique and in sorted order.
Output a single integer: the total number of points the player earns given a maximally-generous scoring engine.
Sample Input 1 | Sample Output 1 |
---|---|
3 4 100 200 300 99 201 240 323 |
20 |
Sample Input 2 | Sample Output 2 |
---|---|
4 3 1000 2000 2500 3000 1103 2598 4000 |
2 |
Sample Input 3 | Sample Output 3 |
---|---|
2 2 100 144 56 100 |
7 |