P27193 [AtCoder] Pizza
普及+
题目描述

Problem Description

JOI Pizza delivers pizza along a circular road that runs through the city center, with a total length of $ d $ meters.

JOI Pizza has $ n $ stores $S_1, \ldots, S_n$ along this circular road. The main store is $ S_1 $. Let $ d_i $ be the distance in meters from $ S_1 $ to $ S_i $ when traveling clockwise along the circular road. $d_2, \ldots, d_n$ are integers between $ 1 $ and $ d - 1 $ inclusive, and all $d_2, \ldots, d_n$ are distinct.

When an order is received, the pizza is baked and delivered from the store with the shortest travel distance to the delivery destination to keep the pizza warm.

The delivery destination is represented by an integer $ k $ between $ 0 $ and $ d - 1 $ inclusive. This means the distance in meters from the main store $ S_1 $ to the delivery destination when traveling clockwise along the circular road is $ k $ meters. Pizza delivery is only allowed along the circular road, and both clockwise and counterclockwise movements are permitted.

For example, if the positions of the stores and delivery destinations are as shown in the figure below (this example corresponds to Example 1 in "Sample Input and Output"):

e7d15f9acc0ef6dedc9a6b1978f6b221.png

The nearest store to delivery destination $ 1 $ is $ S_2 $, so the delivery is made from store $ S_2 $. The travel distance from the store is $ 1 $ meter. Also, the nearest store to delivery destination $ 2 $ is $ S_1 $ (the main store), so the delivery is made from store $ S_1 $. The travel distance from the store is $ 2 $ meters.

Given the total length of the circular road $ d $, the number of stores $ n $, the number of orders $ m $, the positions of stores other than the main store $d_2, \ldots, d_n$, and the delivery destinations $k_1, \ldots, k_m$, create a program that calculates the total sum of travel distances for all deliveries (i.e., the distance from the nearest store to the delivery destination).


Input Format

The first line contains a positive integer $ d $ ($2 \leq d \leq 1,000,000,000 = 10^9$) representing the total length of the circular road. The second line contains a positive integer $ n $ ($2 \leq n \leq 100,000$) representing the number of stores. The third line contains a positive integer $ m $ ($1 \leq m \leq 10,000$) representing the number of orders. The next $ n - 1 $ lines contain integers $d_2, d_3, \ldots, d_n$ ($1 \leq d_i \leq d - 1$) representing the positions of stores other than the main store. The next $ m $ lines contain integers $k_1, k_2, \ldots, k_m$ ($0 \leq k_i \leq d - 1$) representing the delivery destinations.

For 40% of the test cases, $n \leq 10,000$. For another 40% of the test cases, the total travel distance and $ d $ are both $ 1,000,000 $ or less. For all test cases, the total travel distance is $ 1,000,000,000 = 10^9 $ or less.

Output Format

Output consists of one line containing a single integer representing the total sum of travel distances for all deliveries.


Sample Input and Output

Sample Input #1

8
3
2
3
1
4
6

Sample Output #1

3

Sample Input #2

20
4
4
12
8
16
7
7
11
8

Sample Output #2

3

Notes/Hints

Sample Explanation 1


输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
8 3 2 3 1 4 6
样例输出
3