Under construction

Still being built. Things may change

Supply Warehouse Cleanup

Time limit1sMemory limit1024 MB

Summary
Split N boxes into at most M consecutive groups, assign each group to a distinct squad, and minimize the largest per-soldier share of supplies.
Level

Medium7 of 10

Topics
Binary search, Greedy, Prefix sum, Brute force
Solved
No attempts yet

Problem

The supply warehouse has NN supply boxes numbered from 11 to NN, lined up in numerical order. Box ii holds aia_i supplies. The unit in charge of cleanup has MM squads numbered from 11 to MM, and squad jj has bjb_j soldiers.

The commander told the deputy to use the following method. Split the NN boxes into at most MM groups of consecutive boxes. Pick as many squads as there are groups, and assign each group to one squad. The soldiers of that squad clean up all supplies in the group. Each group must contain at least one box.

To keep the work from being pushed onto others, the deputy assigns each soldier a fixed number of supplies to clean up. To make the split as fair as possible, the deputy wants to minimize the number of supplies handled by the soldier with the largest share, while still following the commander's method.

When every soldier is assigned according to the deputy's plan, find the number of supplies handled by the soldier who cleans up the most.

Input

The first line contains the number of boxes NN and the number of squads MM, separated by a space. (1≤N≤500 0001 \leq N \leq 500\,000; 1≤M≤min⁡(N,7)1 \leq M \leq \min(N, 7))

The second line contains the supply counts a1,a2,⋯ ,aNa_1, a_2, \cdots, a_N in each box, separated by spaces. (1≤ai≤1 000 0001 \leq a_i \leq 1\,000\,000)

The third line contains the number of soldiers b1,b2,⋯ ,bMb_1, b_2, \cdots, b_M in each squad, separated by spaces. (1≤bj≤1 000 0001 \leq b_j \leq 1\,000\,000)

Output

Print the number of supplies handled by the soldier who cleans up the most.

Examples1

  1. Example 1

    Input
    3 2
    8 6 4
    3 6
    
    Expected output
    3