fork download
  1. #include <bits/stdc++.h>
  2. #define bug(x) cout<<#x<<'='<<x<<'\n'
  3. #define tc() int tc;cin>>tc;for(int _tc=0;_tc<tc;++_tc)
  4. #define up(i,l,r) for(int i=l;i<=r;++i)
  5. #define down(i,r,l) for(int i=r;i>=l;--i)
  6. #define fw(file) freopen(file,"w",stdout)
  7. #define fr(file) freopen(file,"r",stdin)
  8. #define reset(x) memset(x,0,sizeof(x))
  9. #define pb push_back
  10. #define mp make_pair
  11. #define fi first
  12. #define se second
  13. using namespace std;
  14. typedef long long int ll;
  15. typedef vector<int> vi;
  16. typedef pair<int,int> pii;
  17. typedef vector<pii> vii;
  18.  
  19. string s;
  20.  
  21. int main()
  22. {
  23. ios_base::sync_with_stdio(0);
  24. vector<pair<string, double> > a;
  25. // fr("in.INP");
  26. // fw("out.OUT");
  27. tc()
  28. {
  29. double res=0;
  30. int c, n;
  31. a.clear();
  32. cin >> c >> n;
  33. a.pb({"JD",1.0});
  34. up(i,1,c)
  35. {
  36. double t;
  37. cin >> s >> t;
  38. a.pb({s,t});
  39. }
  40. sort(a.begin(), a.end());
  41. up(i,1,n)
  42. {
  43. double t;
  44. cin >> t >> s;
  45. //bug(t);bug(s);
  46. res += t * (lower_bound(a.begin(), a.end(), mp(s,0.0))->se);
  47. }
  48. cout << fixed << setprecision(6) << res << '\n';
  49. }
  50.  
  51. }
  52.  
Success #stdin #stdout 0s 15248KB
stdin
Standard input is empty
stdout
Standard output is empty