- 问题链接: 稀疏向量
- 问题分析:模拟法解决。
- 程序说明:A数组存第一组向量;res存结果
- 程序代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
class Reader {
static StringTokenizer token =new StringTokenizer("");
static BufferedReader reader =new BufferedReader (new InputStreamReader(System.in)) ;
static String nextLine() throws IOException {
return reader.readLine() ;
}
static String next() throws IOException {
while(!token.hasMoreTokens()) {
token =new StringTokenizer(reader.readLine()) ;
}
return token.nextToken() ;
}
static int nextInt() throws IOException {
return Integer.parseInt(next()) ;
}
static double nextDouble() throws IOException {
return Double.parseDouble(next()) ;
}
}
public class Main {
public static void main(String[] args) throws IOException {
int n = Reader.nextInt();
int a = Reader.nextInt();
int b = Reader.nextInt();
Map<Integer,Integer> A = new HashMap<>();
for(int i=0;i<a;i++) {
int x=Reader.nextInt();
int y=Reader.nextInt();
A.put(x, y);
}
long res = 0L;
for(int i=0;i<b;i++) {
int x=Reader.nextInt();
int y=Reader.nextInt();
if(A.containsKey(x)) {
res+=A.get(x)*y;
}
}
System.out.println(res);
}
}