Problem list
Log in
#icpc00124 · ICPC SWERC 2021

Ice Cream Shop

Gold II 2.0 s 2048 MB

On a beach there are $n$ huts in a perfect line, hut 1 being at the left and hut $i + 1$ being 100 meters to the right of hut $i$, for all $1 \le i \le n - 1$. In hut $i$ there are $p_{i}$ people. There are $m$ ice cream sellers, also aligned in a perfect line with all the huts. The $i-th$ ice cream seller has their shop $x_{i}$ meters to the right of the first hut. All ice cream shops are at distinct locations, but they may be at the same location as a hut. You want to open a new ice cream shop and you wonder what the best location for your shop is. You can place your ice cream shop anywhere on the beach (not necessarily at an integer distance from the first hut) as long as it is aligned with the huts and the other ice cream shops, even if there is already another ice cream shop or a hut at that location. You know that people would come to your shop only if it is strictly closer to their hut than any other ice cream shop. If every person living in the huts wants to buy exactly one ice cream, what is the maximum number of ice creams that you can sell if you place the shop optimally?

Input

The first line contains two integers $n$ and $m$ ($2 \le n \le 200,000$, $1 \le m \le 200,000$) — the number of huts and the number of ice cream sellers. The second line contains $n$ integers $p_{1}$, $p_{2}$, . . . , $p_{n}$ ($1 \le p_{i} \le 10^{9}$) — the number of people in each hut. The third line contains $m$ integers $x_{1}$, $x_{2}$, . . . , $x_{m}$ ($0 \le x_{i} \le 10^{9}$, $x_{i}$̸ = $x_{j}$ for $i$̸ = $j$) — the location of each ice cream shop.

Output

Print the maximum number of ice creams that can be sold by choosing optimally the location of the new shop.

Example 1

Input
3 1
2 5 6
169
Output
7

Example 2

Input
4 2
1 2 7 8
35 157
Output
15

Example 3

Input
4 1
272203905 348354708 848256926 939404176
20
Output
2136015810

Example 4

Input
3 2
1 1 1
300 99
Output
2
Source
ICPC SWERC 2021
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code