CF1618G.Trader Problem

提高+/省选-

通过率:0%

时间限制:4.50s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 xx, then he can trade it for any item (exactly one item) with price not greater than x+kx+k.

Monocarp initially has nn items, the price of the ii-th item he has is aia_i. The character Monocarp is trading with has mm items, the price of the ii-th item they have is bib_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 qq queries. Each query consists of one integer, which is the value of kk, 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 xx for an item of cost not greater than x+kx+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.

Monocarp 正在玩一款电脑游戏(又一次!)。这款游戏具有独特的交易机制。

要与某角色进行交易,Monocarp 必须从自己拥有的物品中选择一件,并用它换取该角色所拥有的某件物品。每件物品都有一个整数价格。若 Monocarp 选择的物品价格为 xx,则他可用它换取任意一件(且仅一件)价格不超过 x+kx+k 的对方物品。

Monocarp 初始拥有 nn 件物品,其中第 ii 件物品的价格为 aia_i;而他正在交易的角色拥有 mm 件物品,其中第 ii 件物品的价格为 bib_i。Monocarp 可以与该角色进行任意多次交易(包括零次),每次交易均需按上述规则,用自己的某件物品换取对方的一件物品。注意:若 Monocarp 在某次交换中获得了一件物品,则此后他可将该物品再次用于交易(因为此时该物品已归他所有);反之亦然:若 Monocarp 用自己的一件物品换得另一件物品,他之后也可通过用其他物品交换,重新获得原先那件物品。

你需要回答 qq 个查询。每个查询给出一个整数 kk,要求计算:在允许每次用价格为 xx 的物品换取价格不超过 x+kx+k 的物品的前提下,Monocarp 经过若干次交易后所能拥有的物品总价格的最大可能值。注意:各查询相互独立——实际交易并不会发生,Monocarp 仅需计算理论上所能达到的最大总价格。

输入格式

The first line contains three integers nn, mm and qq (1≤n,m,q≤2⋅1051 \le n, m, q \le 2 \cdot 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the prices of the items Monocarp has.

The third line contains mm integers b1,b2,…,bmb_1, b_2, \dots, b_m (1≤bi≤1091 \le b_i \le 10^9) — the prices of the items the other character has.

The fourth line contains qq integers, where the ii-th integer is the value of kk for the ii-th query (0≤k≤1090 \le k \le 10^9).

第一行包含三个整数 nn、mm 和 qq(1≤n,m,q≤2⋅1051 \le n, m, q \le 2 \cdot 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)——表示 Monocarp 所拥有的物品的价格。

第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \dots, b_m(1≤bi≤1091 \le b_i \le 10^9)——表示另一角色所拥有的物品的价格。

第四行包含 qq 个整数,其中第 ii 个整数为第 ii 次查询的 kk 值(0≤k≤1090 \le k \le 10^9)。

输出格式

For each query, print one integer — the maximum possible total cost of items Monocarp can have after some sequence of trades, given the value of kk from the query.

对于每个查询,输出一个整数——在给定查询中的 kk 值的情况下,Monocarp 经过若干次交易后所能获得的物品总价值的最大值。

输入输出样例

  • 输入#1

    3 4 5
    10 30 15
    12 31 14 18
    0 1 2 3 4

    输出#1

    55
    56
    60
    64
    64

输入解题思路,AI测评打分。不知道怎么写?

首页