human
PYTHON3 solution for "Monocarp plays a computer game (yet again!). This game has a unique trading mechanics.

To trade with a character, Monocarp has to choose one of the items he possesses and trade it for some item the other character possesses. Each item has an integer price. If Monocarp's chosen item has price x, then he can trade it for any item (exactly one item) with price not greater than x+k.

Monocarp initially has n items, the price of the i-th item he has is a_i. The character Monocarp is trading with has m items, the price of the i-th item they have is b_i. Monocarp can trade with this character as many times as he wants (possibly even zero times), each time exchanging one of his items with one of the other character's items according to the aforementioned constraints. Note that if Monocarp gets some item during an exchange, he can trade it for another item (since now the item belongs to him), and vice versa: if Monocarp trades one of his items for another item, he can get his item back by trading something for it.

You have to answer q queries. Each query consists of one integer, which is the value of k, and asks you to calculate the maximum possible total cost of items Monocarp can have after some sequence of trades, assuming that he can trade an item of cost x for an item of cost not greater than x+k during each trade. Note that the queries are independent: the trades do not actually occur, Monocarp only wants to calculate the maximum total cost he can get.

Input

The first line contains three integers n, m and q (1 ≤ n, m, q ≤ 2 ⋅ 10^5).

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the prices of the items Monocarp has.

The third line contains m integers b_1, b_2, ..., b_m (1 ≤ b_i ≤ 10^9) — the prices of the items the other character has.

The fourth line contains q integers, where the i-th integer is the value of k for the i-th query (0 ≤ k ≤ 10^9).

Output

For each query, print one integer — the maximum possible total cost of items Monocarp can have after some sequence of trades,...":


 Give me a Python code to print one integer — the maximum possible total cost of items Monocarp can have after some sequence of trades,?
assistant
#Here is Python code to print one integer — the maximum possible total cost of items Monocarp can have after some sequence of trades,.
 import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# inf = 18446744073709551615
inf = 4294967295
# md = 10**9+7
md = 998244353

class UnionFind:
    def __init__(self, n, cnt_a, val):
        self.cnt_a = cnt_a
        self.val = val
        self.state = [-1]*n
        self.size_table = [1]*n
        # self.ll = list(range(n))
        self.rr = list(range(1, n+1))
        self.s = sum(val)
        # cntはグループ数
        self.cnt = n

    def root(self, u):
        stack = []
        while self.state[u] >= 0:
            stack.append(u)
            u = self.state[u]
        for v in stack: self.state[v] = u
        return u

    def same(self, u, v):
        return self.root(u) == self.root(v)

    def merge(self, u, v):
        u = self.root(u)
        v = self.root(v)
        if u == v: return False
        du = -self.state[u]
        dv = -self.state[v]
        if du < dv: u, v = v, u
        if du == dv: self.state[u] -= 1
        self.state[v] = u
        self.cnt -= 1
        self.size_table[u] += self.size_table[v]
        # self.ll[u] = min(self.ll[u], self.ll[v])
        self.rr[u] = max(self.rr[u], self.rr[v])
        self.cnt_a[u] += self.cnt_a[v]
        self.s -= val[u]+val[v]
        r = self.rr[u]
        val[u] = cs[r]-cs[r-self.cnt_a[u]]
        self.s += val[u]
        return True

    # グループの要素数
    def size(self, u):
        return self.size_table[self.root(u)]

n, m, q = LI()
aa = LI()
bb = LI()
kk = LI()

ab = []
for a in aa:
    ab.append((a, 1))
for a in bb:
    ab.append((a, 0))

ab.sort()
cs = [0]
cnt_a = []
val...