Businessmen Problems
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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,…,ana1,a2,…,an, and will get an income of xixi 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,…,bmb1,b2,…,bm, and it will get an income of yjyj 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}{a1,a2,…,an} (possibly empty subset), the second company can present any subset of elements from {b1,b2,…,bm}{b1,b2,…,bm} (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 nn (1≤n≤1051≤n≤105)  — the number of elements discovered by ChemForces.

The ii-th of the next nn lines contains two integers aiai and xixi (1≤ai≤1091≤ai≤109, 1≤xi≤1091≤xi≤109)  — the index of the ii-th element and the income of its usage on the exhibition. It is guaranteed that all aiai are distinct.

The next line contains a single integer mm (1≤m≤1051≤m≤105)  — the number of chemicals invented by TopChemist.

The jj-th of the next mm lines contains two integers bjbj and yjyj, (1≤bj≤1091≤bj≤109, 1≤yj≤1091≤yj≤109)  — the index of the jj-th element and the income of its usage on the exhibition. It is guaranteed that all bjbj 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.

Examples
input

Copy
  1. 3
    1 2
    7 2
    3 10
    4
    1 4
    2 4
    3 4
    4 4
output

Copy
  1. 24
input

Copy
  1. 1
    1000000000 239
    3
    14 15
    92 65
    35 89
output

Copy
  1. 408
Note

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 109109, 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.

题意: 给你n个A公司的新元素及价值,再给你m个B公司的新元素及价值,两个公司的元素相同的取较大值,问两家公司元素价值总和

直接用一个map保存下相同元素的较大值,然后遍历相加就可以了

  1. #include <map>
  2. #include <set>
  3. #include <stack>
  4. #include <cmath>
  5. #include <queue>
  6. #include <cstdio>
  7. #include <vector>
  8. #include <string>
  9. #include <cstring>
  10. #include <iostream>
  11. #include <algorithm>
  12. #define debug(a) cout << #a << " " << a << endl
  13. using namespace std;
  14. const int maxn = 1e5 + ;
  15. const int mod = 1e9 + ;
  16. typedef long long ll;
  17. int main(){
  18. std::ios::sync_with_stdio(false);
  19. ll n, m;
  20. while( cin >> n ) {
  21. map<ll,ll> mm;
  22. ll x, y;
  23. for( ll i = ; i < n; i ++ ) {
  24. cin >> x >> y;
  25. if( mm[x] < y ) {
  26. mm[x] = y;
  27. }
  28. }
  29. cin >> m;
  30. for( ll i = ; i < m; i ++ ) {
  31. cin >> x >> y;
  32. if( mm[x] < y ) {
  33. mm[x] = y;
  34. }
  35. }
  36. ll sum = ;
  37. for( map<ll,ll>:: iterator it = mm.begin(); it != mm.end(); it ++ ) {
  38. sum += (*it).second;
  39. }
  40. cout << sum << endl;
  41. }
  42. return ;
  43. }

CF981B Businessmen Problems map 模拟 二十二的更多相关文章

  1. JAVA之旅(二十二)——Map概述,子类对象特点,共性方法,keySet,entrySet,Map小练习

    JAVA之旅(二十二)--Map概述,子类对象特点,共性方法,keySet,entrySet,Map小练习 继续坚持下去吧,各位骚年们! 事实上,我们的数据结构,只剩下这个Map的知识点了,平时开发中 ...

  2. JAVA基础知识总结:一到二十二全部总结

    >一: 一.软件开发的常识 1.什么是软件? 一系列按照特定顺序组织起来的计算机数据或者指令 常见的软件: 系统软件:Windows\Mac OS \Linux 应用软件:QQ,一系列的播放器( ...

  3. (C/C++学习笔记) 二十二. 标准模板库

    二十二. 标准模板库 ● STL基本介绍 标准模板库(STL, standard template library): C++提供的大量的函数模板(通用算法)和类模板. ※ 为什么我们一般不需要自己写 ...

  4. python3.4学习笔记(二十二) python 在字符串里面插入指定分割符,将list中的字符转为数字

    python3.4学习笔记(二十二) python 在字符串里面插入指定分割符,将list中的字符转为数字在字符串里面插入指定分割符的方法,先把字符串变成list然后用join方法变成字符串str=' ...

  5. 条目二十二《切勿修改set或multiset的键》

    条目二十二<切勿修改set或multiset的键> 所有的标准关联容器一样,set和multiset按照一定的顺序来存放自己的元素,而这些容器的正确行为也是建立在其元素保持有序的基础之上的 ...

  6. Alink漫谈(二十二) :源码分析之聚类评估

    Alink漫谈(二十二) :源码分析之聚类评估 目录 Alink漫谈(二十二) :源码分析之聚类评估 0x00 摘要 0x01 背景概念 1.1 什么是聚类 1.2 聚类分析的方法 1.3 聚类评估 ...

  7. [分享] IT天空的二十二条军规

    Una 发表于 2014-9-19 20:25:06 https://www.itsk.com/thread-335975-1-1.html IT天空的二十二条军规 第一条.你不是什么都会,也不是什么 ...

  8. Bootstrap <基础二十二>超大屏幕(Jumbotron)

    Bootstrap 支持的另一个特性,超大屏幕(Jumbotron).顾名思义该组件可以增加标题的大小,并为登陆页面内容添加更多的外边距(margin).使用超大屏幕(Jumbotron)的步骤如下: ...

  9. Web 前端开发精华文章推荐(HTML5、CSS3、jQuery)【系列二十二】

    <Web 前端开发精华文章推荐>2014年第一期(总第二十二期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各类能够提升网站用户体验的优秀 jQuery 插件,展示前沿的 HTML ...

随机推荐

  1. 一文带你彻底理解 JavaScript 原型对象

    一.什么是原型 原型是Javascript中的继承的基础,JavaScript的继承就是基于原型的继承. 1.1 函数的原型对象 在JavaScript中,我们创建一个函数A(就是声明一个函数), 那 ...

  2. DesignPattern系列__05开闭原则

    介绍 开闭原则是编程设计中最基本.最重要的原则. 定义:一个软件实体如类.方法和模块等,应该对扩展(提供方)开放,对修改(使用方)关闭.用抽象构建框架,用实现扩展细节. 也就是说,在需求发生新的变化时 ...

  3. 夯实Java基础(九)——final关键字

    1.前言 Java语言中的final关键字,想必大家都不是很陌生,我们自己用的最多的应该是用来定义常量吧,那么今天我们就来了解final这个关键字的用法,这个关键字还是非常简单的. final从字面意 ...

  4. 使用 Netty 实现一个 MVC 框架

    NettyMVC 上面介绍 Netty 能做是什么时我们说过,相比于 SpringMVC 等框架,Netty 没提供路由等功能,这也契合和 Netty 的设计思路,它更贴近底层.下面我们在 Netty ...

  5. 用HTML5的canvas做一个时钟

    对于H5来说,canvas可以说是它最有特色的一个地方了,有了它之后我们可以随意的在网页上画各种各样的图形,做一些小游戏啊什么的.canvas这个标签的用法,在网上也有特别多的教程了,这里就不作介绍了 ...

  6. 分享我的GD32F450的IAP过程

    最近一个项目使用GD32F450VI+ESP8266需要做远程升级,基本参考正点原子IAP的那一章节,但是在GD32F450上却遇到了问题,无法跳转,然后使用正点原子的开发板stm32f429,以及s ...

  7. vue+element搭建后台管理界面(支持table条件搜索)

    代码地址(如果有帮助,请点个Star) vue:https://github.com/wwt729/ElementUIAdmin-master.git springboot后端:https://git ...

  8. Python爬虫(一)抓取指定的页面

    (以下是在windows环境下的操作,python版本为3) 1.urllib库介绍 官方文档上的解释是: urllib is a package that collects several modu ...

  9. 【MySQL】索引

    什么是索引 索引就好比是书的目录,可以显著提高数据库查询的效率.例如像一本很厚的书,在没有目录的情况下要查到你想要看的知识点,都不知要找到什么时候,但通过目录我们可以很快的查询到对应的内容. 索引的数 ...

  10. maven替换中央仓库,阿里云镜像下载及自定义本地仓库位置

    maven替换中央仓库- 阿里云 在国内访问Maven仓库,下载速度太慢.下面是将中央仓库替换成阿里云的中央仓库的方法.国内还有其他的公共仓库,自己选择.  在你下载的maven版本-conf-set ...