-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathBusinessProblem.java
More file actions
28 lines (28 loc) · 975 Bytes
/
Copy pathBusinessProblem.java
File metadata and controls
28 lines (28 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// problem: https://codeforces.com/problemset/problem/981/B
import java.util.Scanner;
import java.util.HashMap;
public class BusinessProblem{
public static void main(String[] args){
Scanner sObj = new Scanner(System.in);
int n = sObj.nextInt();
HashMap<Long,Long> hMap = new HashMap<Long,Long>();
Long temp;
Long value;
for(int z=0; z<n; z++){
temp = sObj.nextLong();
value = sObj.nextLong();
if(hMap.containsKey(temp)) if(hMap.get(temp) > value) continue;
hMap.put(temp, value);
}
int m = sObj.nextInt();
for(int zz=0; zz<m; zz++){
temp = sObj.nextLong();
value = sObj.nextLong();
if(hMap.containsKey(temp)) if(hMap.get(temp) > value) continue;
hMap.put(temp, value);
}
Long total = (long) 0;
for(Long ele: hMap.values()) total += ele;
System.out.println(total);
}
}