自己写的一直是60分
下面的100分参考自该链接
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args){
int n=0, a=0, b=0;
try {
n = Reader.nextInt();
a = Reader.nextInt();
b = Reader.nextInt();
} catch (IOException e) {
e.printStackTrace();
}
HashMap<Integer,Integer> arr=new HashMap<>();
long sum=0;
int k=0,g=0;
for(int i=0;i<a;i++)
{
try {
k = Reader.nextInt();
g = Reader.nextInt();
} catch (IOException e) {
e.printStackTrace();
}
arr.put(k,g);
}
for(int i=0;i<b;i++)
{
try {
k = Reader.nextInt();
g = Reader.nextInt();
} catch (IOException e) {
e.printStackTrace();
}
if(arr.containsKey(k))
{
sum+=arr.get(k)*g;
}
}
System.out.println(sum);
}
}
class Reader {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer tokenizer = new StringTokenizer("");
static String nextLine() throws IOException{// 读取下一行字符串
return reader.readLine();
}
static String next() throws IOException {// 读取下一个字符串
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {// 读取下一个int型数值
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {// 读取下一个double型数值
return Double.parseDouble(next());
}
}