Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2018
3,739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4. map<string,int> d;
  5. int arr[100005],cost[100005],group[100005];
  6. int main()
  7. {
  8.     int n,k,m;
  9.     cin >> n >> k >> m;
  10.     for (int i=1;i<=n;i++)
  11.     {
  12.         string s;
  13.         cin >> s;
  14.         d[s]=i;
  15.     }
  16.     for (int i=1;i<=n;i++)
  17.     {
  18.         cin >> arr[i];
  19.         cost[i]=(1<<30);
  20.     }
  21.     for (int i=1;i<=k;i++)
  22.     {
  23.         int x;
  24.         cin >> x;
  25.         while (x--)
  26.         {
  27.             int a;
  28.             cin >> a;
  29.             group[a]=i;
  30.             cost[i]=min(cost[i],arr[a]);
  31.         }
  32.     }
  33.     long long ans=0;
  34.     while (m--)
  35.     {
  36.         string s;
  37.         cin >> s;
  38.         ans+=cost[group[d[s]]];
  39.     }
  40.     cout << ans;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement