C. New Year Book Reading

 

http://codeforces.com/contest/500/problem/C

 

simulation

 

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4 
 5     public static void main(String[] args) {
 6         Scanner io = new Scanner(System.in);
 7         int n = io.nextInt(), m = io.nextInt();
 8         int[] w = new int[n + 1], b = new int[n + 1];
 9         for (int i = 1; i <= n; i++) {
10             w[i] = io.nextInt();
11             b[i] = -1;
12         }
13         int ans = 0;
14         for (int i = 0, a; i < m; i++) {
15             a = io.nextInt();
16             for (int j = 1; j <= n; j++) if (b[j] > b[a]) ans += w[j];
17             b[a] = i;
18         }
19         System.out.println(ans);
20     }
21 
22 }

 

Guess you like

Origin www.cnblogs.com/towerbird/p/11410177.html
Recommended