博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF981B Businessmen Problems map 模拟 二十二
阅读量:6848 次
发布时间:2019-06-26

本文共 3728 字,大约阅读时间需要 12 分钟。

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 (1n1051≤n≤105)  — the number of elements discovered by ChemForces.

The ii-th of the next nn lines contains two integers aiai and xixi (1ai1091≤ai≤109, 1xi1091≤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 (1m1051≤m≤105)  — the number of chemicals invented by TopChemist.

The jj-th of the next mm lines contains two integers bjbj and yjyj, (1bj1091≤bj≤109, 1yj1091≤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 #include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define debug(a) cout << #a << " " << a << endlusing namespace std;const int maxn = 1e5 + 10;const int mod = 1e9 + 7;typedef long long ll;int main(){ std::ios::sync_with_stdio(false); ll n, m; while( cin >> n ) { map
mm; ll x, y; for( ll i = 0; i < n; i ++ ) { cin >> x >> y; if( mm[x] < y ) { mm[x] = y; } } cin >> m; for( ll i = 0; i < m; i ++ ) { cin >> x >> y; if( mm[x] < y ) { mm[x] = y; } } ll sum = 0; for( map
:: iterator it = mm.begin(); it != mm.end(); it ++ ) { sum += (*it).second; } cout << sum << endl; } return 0;}

 

转载于:https://www.cnblogs.com/l609929321/p/9250018.html

你可能感兴趣的文章
box-sizing属性的的用法
查看>>
应如何修改QUICKSORT,才能使其按非增序进行排序?
查看>>
Android开发之自定义局部导航菜单
查看>>
EL函数以及自定义标签的应用
查看>>
【合集】zz数组与指针的艺术--深入探索c/c++数组与指针
查看>>
ionic的安装及简单的应用
查看>>
python练习册 0002随机生成验证
查看>>
spring帝国-开篇
查看>>
【数论】【欧拉函数】【筛法求素数】【乘法逆元】【快速幂取模】bzoj2186 [Sdoi2008]沙拉公主的困惑...
查看>>
【floyd】CODEVS 1077 多源最短路
查看>>
windows Driver 查询指定键值
查看>>
为什么要选择IOS
查看>>
【模板】归并排序(+求逆序对)
查看>>
js scroll事件
查看>>
第三次作业
查看>>
CSS选择器实例
查看>>
axios
查看>>
Android中如何禁止音量调节至静音
查看>>
树莓派安装mjpg-streamer视频监控 分类: Raspberry P...
查看>>
HDU1892 See you~
查看>>