fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n, x, t=0;
  6. cin>>n>>x;
  7. int arr[n];
  8. string s[n+1];
  9. string a[x+1];
  10. for(int i=1; i<=n; i++){
  11. cin>>s[i];
  12. }
  13. for(int i=1; i<=x; i++){
  14. cin>>a[i];
  15. }
  16. for(int i=0; i<n; i++){
  17. cin>>arr[i];
  18. }
  19. for(int i=1; i<=n; i++){
  20. for(int j=1; j<=x/*2*/; j++){
  21. if(s[i]==a[j]){
  22. t+=arr[j];
  23. break;
  24. }
  25. if(x==j){
  26. t+=arr[0];
  27. }
  28. }
  29. }
  30. cout<<t;
  31. }
Success #stdin #stdout 0.01s 5304KB
stdin
3 2
code queen atcoder
king queen
10 1 1
stdout
21