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

#TP0000028. Mua sơn cho các phòng (Room Painting)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Mua sơn cho các phòng (Room Painting)

Room Painting

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Joe is painting mm rooms using mm different paint colors. For color jj, he needs exactly bjb_j microlitres of paint. The shop offers cans in nn fixed sizes a1,…,ana_1,\ldots,a_n, measured in microlitres.

Joe buys exactly one can for each color. The shop has an unlimited supply of every can size and can fill each with any color, so the same size may be selected for different colors. A chosen can must contain at least the required amount. It is guaranteed that some offered can size is large enough for every color. Find the minimum total paint wasted, in microlitres.

Input

  • The first line contains n,mn,m, the numbers of offered can sizes and needed paint colors.
  • Each of the next nn lines contains one integer aia_i, the size of a can offered by the shop, in microlitres.
  • Each of the final mm lines contains one integer bjb_j, the amount of paint needed for color jj, in microlitres.

Output

Print one integer: the minimum total number of wasted microlitres.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤81\le n,m\le 8; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for every element; max⁡1≤j≤mbj≤max⁡1≤i≤nai\max_{1\le j\le m}b_j\le\max_{1\le i\le n}a_i.
  • Subtask 2 (30 points): 1≤n,m≤13001\le n,m\le 1300; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for every element; max⁡1≤j≤mbj≤max⁡1≤i≤nai\max_{1\le j\le m}b_j\le\max_{1\le i\le n}a_i.
  • Subtask 3 (50 points): 1≤n,m≤1000001\le n,m\le 100000; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for every element; max⁡1≤j≤mbj≤max⁡1≤i≤nai\max_{1\le j\le m}b_j\le\max_{1\le i\le n}a_i.

Examples

Input

3 2
5
7
9
6
8

Output

2

Explanation

The first color needs 66 microlitres, so the smallest suitable can has size 77, wasting 7−6=17-6=1. The second needs 88 microlitres, so a size-99 can wastes 9−8=19-8=1. The minimum total waste is 1+1=21+1=2 microlitres.