原题链接
本题只用了一个HashMap来存储,差点超过空间,有点极限。
import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, a, b;
n = sc.nextInt();
a = sc.nextInt();
b = sc.nextInt();
HashMap<Integer, Long> hm1 = new HashMap<Integer, Long>();
for (int i = 0; i < a; i++) {
int key = sc.nextInt();
long value = sc.nextInt();
hm1.put(key, value);
}
long res = 0;
for (int i = 0; i < b; i++) {
int key = sc.nextInt();
long value = sc.nextInt();
if(hm1.containsKey(key))
res += hm1.get(key) * value;
}
System.out.println(res);
sc.close();
}
}