fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. const int N = 1e4 + 4;
  4. const int M = 1e4 + 4;
  5. const int MAX = 1 << 22;
  6. int m1 , m2 , m3;
  7. string arr1[N];
  8. string arr2[N];
  9. string arr3[N];
  10. int str1[N];
  11. int str2[N];
  12. int str3[N];
  13. vector < pair < int , int > > v[MAX];
  14. set < pair < pair < int , int > , int > > used;
  15. int n;
  16. map < string , int > ma1;
  17. map < string , int > ma2;
  18. map < string , int > ma3;
  19. int main(){
  20. cin >> m1;
  21. for(int i = 1 ; i <= m1 ; ++i){
  22. cin >> arr1[i] >> str1[i];
  23. ma1[arr1[i]] = i;
  24. }
  25. cin >> m2;
  26. for(int i = 1 ; i <= m2 ; ++i){
  27. cin >> arr2[i] >> str2[i];
  28. ma2[arr2[i]] = i;
  29. }
  30. cin >> m3;
  31. for(int i = 1 ; i <= m3 ; ++i){
  32. cin >> arr3[i] >> str3[i];
  33. ma3[arr3[i]] = i;
  34. }
  35. for(int i = 1 ; i <= m1 ; ++i){
  36. for(int j = 1 ; j <= m2 ; ++j){
  37. v[str1[i] + str2[j]].emplace_back(make_pair(i , j));
  38. }
  39. }
  40. cin >> n;
  41. while(n--){
  42. string a , b , c;
  43. cin >> a >> b >> c;
  44. int i = ma1[a];
  45. int j = ma2[b];
  46. int k = ma3[c];
  47. int strong = str1[i] + str2[j] + str3[k] + 1;
  48. for(int i = 1 ; i <= m3 ; ++i){
  49. if(str3[i] <= strong){
  50. for(auto it : v[strong - str3[i]]){
  51. pair < pair < int , int > , int > temp = {it , i};
  52. if(used.find(temp) == used.end()){
  53. used.insert(temp);
  54. cout << arr1[it.first] << " " << arr2[it.second] << " " << arr3[i] << endl;
  55. i = m3 + 1;
  56. break;
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
Success #stdin #stdout 0.05s 52536KB
stdin
Standard input is empty
stdout
Standard output is empty