CF981B.Businessmen Problems

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.

In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.

All elements are enumerated with integers. The ChemForces company has discovered nn distinct chemical elements with indices a1,a2,…,ana_1, a_2, \ldots, a_n, and will get an income of xix_i Berland rubles if the ii-th element from this list is in the set of this company.

The TopChemist company discovered mm distinct chemical elements with indices b1,b2,…,bmb_1, b_2, \ldots, b_m, and it will get an income of yjy_j Berland rubles for including the jj-th element from this list to its set.

In other words, the first company can present any subset of elements from a1,a2,…,an{a_1, a_2, \ldots, a_n} (possibly empty subset), the second company can present any subset of elements from b1,b2,…,bm{b_1, b_2, \ldots, b_m} (possibly empty subset). There shouldn't be equal elements in the subsets.

Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.

两家著名的竞争公司 ChemForces 和 TopChemist 决定在展览上展示各自最近发现的化学元素集合。然而,他们知道:任何一种元素都不应同时出现在两家公司的集合中。

为避免这种情况,两家公司的代表决定就各自应展出的集合达成一项协议,使得两家公司的总收入最大化。

所有元素均用整数编号。ChemForces 公司发现了 nn 种互不相同的化学元素,其编号为 a1,a2,…,ana_1, a_2, \ldots, a_n;若该公司在其展出集合中包含该列表中的第 ii 个元素,则可获得 xix_i 白俄罗斯卢布的收入。

TopChemist 公司发现了 mm 种互不相同的化学元素,其编号为 b1,b2,…,bmb_1, b_2, \ldots, b_m;若该公司在其展出集合中包含该列表中的第 jj 个元素,则可获得 yjy_j 白俄罗斯卢布的收入。

换言之,第一家公司可从集合 {a1,a2,…,an}\{a_1, a_2, \ldots, a_n\} 中任选一个子集(可以为空集)进行展出;第二家公司可从集合 {b1,b2,…,bm}\{b_1, b_2, \ldots, b_m\} 中任选一个子集(可以为空集)进行展出。但这两个子集不能包含相同的元素。

请帮助两家公司的代表选出满足“无公共元素”约束且总收入最大的两个集合。

输入格式

The first line contains a single integer nn (1≤n≤1051 \leq n \leq 10^5) — the number of elements discovered by ChemForces.

The ii-th of the next nn lines contains two integers aia_i and xix_i (1≤ai≤1091 \leq a_i \leq 10^9, 1≤xi≤1091 \leq x_i \leq 10^9) — the index of the ii-th element and the income of its usage on the exhibition. It is guaranteed that all aia_i are distinct.

The next line contains a single integer mm (1≤m≤1051 \leq m \leq 10^5) — the number of chemicals invented by TopChemist.

The jj-th of the next mm lines contains two integers bjb_j and yjy_j, (1≤bj≤1091 \leq b_j \leq 10^9, 1≤yj≤1091 \leq y_j \leq 10^9) — the index of the jj-th element and the income of its usage on the exhibition. It is guaranteed that all bjb_j are distinct.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)—— ChemForces 发现的元素个数。

接下来的 nn 行中,第 ii 行包含两个整数 aia_i 和 xix_i(1≤ai≤1091 \leq a_i \leq 10^9,1≤xi≤1091 \leq x_i \leq 10^9)—— 分别表示第 ii 个元素的编号及其在展览中使用所带来的收益。保证所有 aia_i 互不相同。

下一行包含一个整数 mm(1≤m≤1051 \leq m \leq 10^5)—— TopChemist 发明的化学药品个数。

接下来的 mm 行中,第 jj 行包含两个整数 bjb_j 和 yjy_j(1≤bj≤1091 \leq b_j \leq 10^9,1≤yj≤1091 \leq y_j \leq 10^9)—— 分别表示第 jj 种化学药品的编号及其在展览中使用所带来的收益。保证所有 bjb_j 互不相同。

输出格式

Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.

在确保两个集合不包含任何相同元素的前提下,选择两个公司的集合,输出所能获得的最大总收入。

输入输出样例

  • 输入#1

    3
    1 2
    7 2
    3 10
    4
    1 4
    2 4
    3 4
    4 4

    输出#1

    24
  • 输入#2

    1
    1000000000 239
    3
    14 15
    92 65
    35 89

    输出#2

    408

说明/提示

In the first example ChemForces can choose the set (3,73, 7), while TopChemist can choose (1,2,41, 2, 4). This way the total income is (10+2)+(4+4+4)=24(10 + 2) + (4 + 4 + 4) = 24.

In the second example ChemForces can choose the only element 10910^9, while TopChemist can choose (14,92,3514, 92, 35). This way the total income is (239)+(15+65+89)=408(239) + (15 + 65 + 89) = 408.

在第一个例子中,ChemForces 可以选择集合 (3,7)(3, 7),而 TopChemist 可以选择 (1,2,4)(1, 2, 4)。此时总收入为 (10+2)+(4+4+4)=24(10 + 2) + (4 + 4 + 4) = 24。

在第二个例子中,ChemForces 只能选择唯一元素 10910^9,而 TopChemist 可以选择 (14,92,35)(14, 92, 35)。此时总收入为 (239)+(15+65+89)=408(239) + (15 + 65 + 89) = 408。

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

首页