#include #include using namespace std; using LL = long long; using P = pair; using Graph = vector>; const int INF = 1 << 29; const long long LINF = 1LL << 60; #define all(x) (x).begin(), (x).end() #define rep(i,n) for(int i = 0; i < (n); ++i) templatevoid chmin(T&a, T b){if(a > b) a = b;} templatevoid chmax(T&a, T b){if(a < b) a = b;} int main(){ int N, M, X; cin >> N >> M >> X; vector> problem(M,vector()); //ジャンル別に問題を整理 for(int i = 0; i < N; ++i){ int A, B; cin >> A >> B; --B; problem[B].push_back(A); } //その問題を降順に整理 for(int i = 0; i < M; ++i){ sort(problem[i].rbegin(), problem[i].rend()); } //優先度の高い各ジャンルの一番高い得点に+X for(int i = 0; i < M; ++i) problem[i][0] += X; vector ALL; for(int i = 0; i < M; ++i){ for(auto v : problem[i]){ ALL.push_back(v); } } sort(ALL.rbegin(), ALL.rend()); vector S(N+1, 0); for(int i = 0; i < N; ++i) S[i+1] = S[i] + ALL[i]; int K; cin >> K; int res = 0; for(int i = 0; i < K; ++i){ int C; cin >> C; res += S[C]; } cout << res << endl; }