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 ...
随机推荐
- 为什么for循环可以遍历list:Python中迭代器与生成器
1 引言 只要你学了Python语言,就不会不知道for循环,也肯定用for循环来遍历一个列表(list),那为什么for循环可以遍历list,而不能遍历int类型对象呢?怎么让一个自定义的对象可遍历 ...
- go 学习笔记之工作空间
搭建好 Go 的基本环境后,现在可以正式开始 Go 语言的学习之旅,初学时建议在默认的 GOPATH 工作空间规范编写代码,基本目录结构大概是这个样子. . |-- bin | `-- hello.e ...
- python协程详解
目录 python协程详解 一.什么是协程 二.了解协程的过程 1.yield工作原理 2.预激协程的装饰器 3.终止协程和异常处理 4.让协程返回值 5.yield from的使用 6.yield ...
- Android 属性动画实战
什么是属性动画? 属性动画可以通过直接更改 View 的属性来实现 View 动画.例如: 通过不断的更改 View 的坐标来实现让 View 移动的效果: 通过不断的更改 View 的背景来实现让 ...
- .net持续集成测试篇之Nunit参数化测试
系列目录 在进行单元测试的时候,很多时候,很多时候我们都是在单元测试方法内部提供特定的值,但是这样测试往往造成样本数不足从而导致覆盖的结果不够全面,很多时候我们更想提供来自外部的,满足条件的一组值来进 ...
- 【Java例题】2.5 温度转换
5.输入华氏温度, 用下列公式将其转换为摄氏温度并输出. C=5/9(F-32). package study; import java.util.Scanner; public class demo ...
- C#.Net实现AutoCAD块属性提取
https://blog.csdn.net/dengyiyu/article/details/2201175 本文主要给大家介绍一下SmartSoft中用C#.Net实现AutoCAD块属性提取的方法 ...
- StudyAndroid.1
目标: 手动创建第一个Activity 开发环境: Android Studio 3.3.1 Build #AI-182.5107.16.33.5264788, built on January 29 ...
- 常用的python内置方法
all ( ) 循环参数,参数全为真就返回Ture any() 只要有一个 ...
- 积性函数&线性筛&欧拉函数&莫比乌斯函数&因数个数&约数个数和
只会搬运YL巨巨的博客 积性函数 定义 积性函数:对于任意互质的整数a和b有性质f(ab)=f(a)f(b)的数论函数. 完全积性函数:对于任意整数a和b有性质f(ab)=f(a)f(b)的数论函数 ...