#include using namespace std; #if __has_include() #include using namespace atcoder; using mint = modint1000000007; #endif using ll = long long; using ld = long double; const ll INF = 1ll<<60; const ld EPS = 1.0/1e9; #define endl "\n" #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #define del(x) sort(all(x)); x.erase(unique(all(x)),x.end()); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n,m,x; cin >> n >> m >> x; vector>que(m); rep(i,0,n){ ll a,b; cin >> a >> b; b--; que[b].push(a); } queue>use; priority_queue>w; mapf; rep(i,0,m){ if(!que[i].empty() && que[i].top()>=x){ w.push({que[i].top()+x,i,1}); que[i].pop(); f[i]=true; } } rep(i,0,m){ while(!que[i].empty()&& que[i].top()>=x){ w.push({que[i].top(),i,0}); que[i].pop(); f[i]=true; } } priority_queue>h; rep(i,0,m){ if(!f[i] && !que[i].empty()){ h.push({que[i].top()+x,i,1}); que[i].pop(); } } rep(i,0,m){ while(!que[i].empty()){ h.push({que[i].top(),i,0}); que[i].pop(); } } while(!w.empty()){ ll p,q,r; tie(p,q,r)=w.top(); if(r) p-=x; use.push({p,q}); w.pop(); } while(!h.empty()){ ll p,q,r; tie(p,q,r)=h.top(); if(r) p-=x; use.push({p,q}); h.pop(); } vectorsum(n+1); vectorind(n+1); setst; rep(i,0,n){ sum[i+1]+=sum[i]; sum[i+1]+=use.front().first; st.insert(use.front().second); ind[i+1]=st.size(); use.pop(); } ll ans=0; ll k; cin >> k; rep(i,0,k){ ll p=0; ll c; cin >> c; p+=sum[c]; p+=ind[c]*x; ans+=p; } cout << ans << endl; }