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
3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4
output

Copy
24
input

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

Copy
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保存下相同元素的较大值,然后遍历相加就可以了

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e5 + ;
const int mod = 1e9 + ;
typedef long long ll;
int main(){
std::ios::sync_with_stdio(false);
ll n, m;
while( cin >> n ) {
map<ll,ll> mm;
ll x, y;
for( ll i = ; i < n; i ++ ) {
cin >> x >> y;
if( mm[x] < y ) {
mm[x] = y;
}
}
cin >> m;
for( ll i = ; i < m; i ++ ) {
cin >> x >> y;
if( mm[x] < y ) {
mm[x] = y;
}
}
ll sum = ;
for( map<ll,ll>:: iterator it = mm.begin(); it != mm.end(); it ++ ) {
sum += (*it).second;
}
cout << sum << endl;
}
return ;
}

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. go杂货铺

    json序列化 内存中变成可存储或传输的过程称之为序列化(dict,split,struct转string) package main import ( "encoding/json&quo ...

  2. 有容云-PPT | 当微服务遇见容器

    编者注: 本文为10月29日有容云高级技术顾问龙淼在Docker Live时代线下系列-广州站中演讲的PPT,本次线下沙龙为有容云倾力打造Docker Live时代系列主题线下沙龙,每月一期畅聊容器技 ...

  3. Ubuntu 磁盘挂载错误

    一.错误 报错原因: 在删除或者复制移动时,磁盘或者u盘等外接硬件设备,忽然掉落(断掉,接口松动),在次挂载磁盘时就会出现错误 错误日志: $MFTMirr does not match $MFT ( ...

  4. 作为前端的你,CC游戏开发可以上车

    1. 初来乍到 打开 Cocos Creator 点击新建空白项目,在默认布局的左下区域,一个黄黄assets文件夹映入眼帘.作为前端的你对这个文件是不是再熟悉不过了.是的,和你想象的一样,开发游戏中 ...

  5. java高并发系列 - 第23天:JUC中原子类,一篇就够了

    这是java高并发系列第23篇文章,环境:jdk1.8. 本文主要内容 JUC中的原子类介绍 介绍基本类型原子类 介绍数组类型原子类 介绍引用类型原子类 介绍对象属性修改相关原子类 预备知识 JUC中 ...

  6. Hyper-V虚拟机上安装Ubuntu16.04/Ubuntu18.04.2LTS,搭建GitLab

    我的电脑系统是win10,内存8g如下 一开始是装的Ubuntu18.04.2LTS, gitlab-ce_12.1.3-ce.0_amd64.deb,每次能够安装成功,但是修改完ip后,运行gitl ...

  7. Qt基于sqlite数据库的管理小软件

    闲来无事,写了一个基于sqlite的数据库管理小软件. 先上图 中心思想就是: 创建一个数据库 然后每一个分组对应一个数据表 然后遍历该数据表.将名字以treewidgetItem显示出来.添加删除实 ...

  8. [转] java开源游戏

    收藏一下   triplea  Triplea是一个开放源码的boardgame.它允许玩家选择各种各样的战略版图游戏(如:轴心国或同盟军).TripleA引擎支持联网对战,支持声音,支持使用XML文 ...

  9. 重学计算机组成原理(五)- "旋转跳跃"的指令实现

    CPU执行的也不只是一条指令,一般一个程序包含很多条指令 因为有if-else.for这样的条件和循环存在,这些指令也不会一路平直执行下去. 一个计算机程序是怎么被分解成一条条指令来执行的呢 1 CP ...

  10. centos7.x 安装系统/配置网络/设置主机名

    1.安装系统     系统的安装就不多说了,自行查找百度,如:https://www.cnblogs.com/wcwen1990/p/7630545.html   2.配置网络(局域网上网) 修改配置 ...