欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF981B.Businessmen Problems
Businessmen Problems
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 distinct chemical elements with indices , and will get an income of Berland rubles if the -th element from this list is in the set of this company.
The TopChemist company discovered distinct chemical elements with indices , and it will get an income of Berland rubles for including the -th element from this list to its set.
In other words, the first company can present any subset of elements from (possibly empty subset), the second company can present any subset of elements from (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.
Input
The first line contains a single integer () — the number of elements discovered by ChemForces.
The -th of the next lines contains two integers and (, ) — the index of the -th element and the income of its usage on the exhibition. It is guaranteed that all are distinct.
The next line contains a single integer () — the number of chemicals invented by TopChemist.
The -th of the next lines contains two integers and , (, ) — the index of the -th element and the income of its usage on the exhibition. It is guaranteed that all are distinct.
Output
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.
Note
In the first example ChemForces can choose the set (), while TopChemist can choose (). This way the total income is .
In the second example ChemForces can choose the only element , while TopChemist can choose (). This way the total income is .
Samples
3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4
24
1
1000000000 239
3
14 15
92 65
35 89
408
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |