CF981B Businessmen Problems map 模拟 二十二
2 seconds
256 megabytes
standard input
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.
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.
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.
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
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 模拟 二十二的更多相关文章
- JAVA之旅(二十二)——Map概述,子类对象特点,共性方法,keySet,entrySet,Map小练习
JAVA之旅(二十二)--Map概述,子类对象特点,共性方法,keySet,entrySet,Map小练习 继续坚持下去吧,各位骚年们! 事实上,我们的数据结构,只剩下这个Map的知识点了,平时开发中 ...
- JAVA基础知识总结:一到二十二全部总结
>一: 一.软件开发的常识 1.什么是软件? 一系列按照特定顺序组织起来的计算机数据或者指令 常见的软件: 系统软件:Windows\Mac OS \Linux 应用软件:QQ,一系列的播放器( ...
- (C/C++学习笔记) 二十二. 标准模板库
二十二. 标准模板库 ● STL基本介绍 标准模板库(STL, standard template library): C++提供的大量的函数模板(通用算法)和类模板. ※ 为什么我们一般不需要自己写 ...
- python3.4学习笔记(二十二) python 在字符串里面插入指定分割符,将list中的字符转为数字
python3.4学习笔记(二十二) python 在字符串里面插入指定分割符,将list中的字符转为数字在字符串里面插入指定分割符的方法,先把字符串变成list然后用join方法变成字符串str=' ...
- 条目二十二《切勿修改set或multiset的键》
条目二十二<切勿修改set或multiset的键> 所有的标准关联容器一样,set和multiset按照一定的顺序来存放自己的元素,而这些容器的正确行为也是建立在其元素保持有序的基础之上的 ...
- Alink漫谈(二十二) :源码分析之聚类评估
Alink漫谈(二十二) :源码分析之聚类评估 目录 Alink漫谈(二十二) :源码分析之聚类评估 0x00 摘要 0x01 背景概念 1.1 什么是聚类 1.2 聚类分析的方法 1.3 聚类评估 ...
- [分享] IT天空的二十二条军规
Una 发表于 2014-9-19 20:25:06 https://www.itsk.com/thread-335975-1-1.html IT天空的二十二条军规 第一条.你不是什么都会,也不是什么 ...
- Bootstrap <基础二十二>超大屏幕(Jumbotron)
Bootstrap 支持的另一个特性,超大屏幕(Jumbotron).顾名思义该组件可以增加标题的大小,并为登陆页面内容添加更多的外边距(margin).使用超大屏幕(Jumbotron)的步骤如下: ...
- Web 前端开发精华文章推荐(HTML5、CSS3、jQuery)【系列二十二】
<Web 前端开发精华文章推荐>2014年第一期(总第二十二期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各类能够提升网站用户体验的优秀 jQuery 插件,展示前沿的 HTML ...
随机推荐
- hdoj 4712 Hamming Distance(靠人品过的)
我先解释一下汉明距离 以下来自百度百科 在信息论中,两个等长字符串之间的汉明距离是两个字符串对应位置的字符不同的个数.换句话说,它就是将 一个字符串变换成另外一个字符串所需要替换的字符个数. 例如: ...
- linux下pip的安装
---恢复内容开始--- 1 输入apt-cache search wxpython 如果有返回信息 则输入 sudo apt-get install python-tools 2 否则 1.添加软件 ...
- 什么是redis的缓存雪崩与缓存穿透
今天来分享一下Redis几道常见的面试题: 如何解决缓存雪崩? 如何解决缓存穿透? 如何保证缓存与数据库双写时一致的问题? 一.缓存雪崩 1.1 什么是缓存雪崩? 首先我们先来回答一下我们为什么要用缓 ...
- 荔枝FM前端面试题
最近接到了荔枝FM的面试通知,遗憾的是没有拿到offer,但是这次面试呢,还是收获很大的,下面就来给大家说说我遇到的面试题 一面 一面是直接发了一套面试题到邮箱,开启了防作弊的,限时20分钟做完,下面 ...
- Python 使用k-means方法将列表中相似的句子聚为一类
由于今年暑假在学习一些自然语言处理的东西,发现网上对k-means的讲解不是很清楚,网上大多数代码只是将聚类结果以图片的形式呈现,而不是将聚类的结果表示出来,一下代码将老师给的代码和网上的代码结合了一 ...
- 值得花费一周研究的算法 -- KMP算法(indexOf)
KMP算法是由三个科学家(kmp分别是他们名字的首字母)创造出来的一种字符串匹配算法. 所解决的问题: 求文本字符串text内寻找第一次出现字符串s的下标,若未出现返回-1. 例如 text : &q ...
- Amazon S3
Amazon S3 是什么? Amazon S3 是亚马逊推出的一款存储服务,名为 Amazon Simple Storage Service,即亚马逊简单存储服务. 有些 S3 的概念需要了解一下: ...
- Yii的srbac拓展中“用户已经获授权项”无法查看
Yii的srbac拓展中“用户已经获授权项”点下拉框,选择一个有权限的用户时,根本无法列出权限. 原因是srbac把数据库的表中的ID默认为数字,像 123这样,但如果不是数字像这样 'y0f22ff ...
- python接口测试入门1-什么是接口测试
为什么要做接口测试 在日常开发过程中,有人做前端开发,有人负责后端开发.接口就是连接前后台,由于前端开发和后端开发的速度可能不一样,例如后端开发好了,但是前端没有开发.那么我们是不是就不需要测试呢?一 ...
- Go-json解码到结构体-踩坑
package main import ( "encoding/json" "fmt" ) type User struct { Name string `js ...