PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000022. Mua hộp kẹo lưu niệm (Souvenirs)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Mua hộp kẹo lưu niệm (Souvenirs)

Souvenirs

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A souvenir shop sells nn boxes of candy. Box ii costs aia_i yen and contains exactly aia_i pieces of candy. Takahashi wants to buy mm boxes and give one to each of mm people.

Person jj must receive a box containing at least bjb_j pieces. Each box may be purchased and assigned only once. Determine the minimum total cost of satisfying everybody. If it is impossible, print -1.

Input

  • The first line contains n,mn,m, the number of available boxes and recipients, with m≤nm\le n.
  • The second line contains nn integers a1,…,ana_1,\ldots,a_n, both the price and the candy count of each box.
  • The third line contains mm integers b1,…,bmb_1,\ldots,b_m, each person's minimum candy requirement.

Output

Print one integer: the minimum total price, or -1 if no valid assignment exists.

Subtasks

  • Subtask 1 (20 points): 1≤m≤n≤71\le m\le n\le 7; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for every element.
  • Subtask 2 (30 points): 1≤m≤n≤16001\le m\le n\le 1600; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for every element.
  • Subtask 3 (50 points): 1≤m≤n≤2000001\le m\le n\le 200000; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for every element.

Examples

Input

4 2
3 4 5 4
1 4

Output

7

Explanation

The person requiring at least 11 candy can receive the box costing 33, which contains 33 candies. The person requiring at least 44 candies can receive either box costing 44. The total cost is 3+4=73+4=7. There is no cheaper box satisfying the second person, so the minimum is 77.