CF1618G Trader Problem

Description

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 Format

N/A

Output Format

N/A