fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define sd(a) scanf("%d",&a)
  5. #define ss(a) scanf("%s",a)
  6. #define sl(a) scanf("%lld",&a)
  7. #define clr(a) memset(a,0,sizeof(a))
  8. #define debug(a) printf("check%d\n",a)
  9. #define F first
  10. #define S second
  11. #define mp make_pair
  12. #define pb push_back
  13. #define ll long long
  14. #define MAX 2000005
  15.  
  16. vector < pair<ll,ll> > V;
  17. map <ll ,bool> M;
  18.  
  19. int main(){
  20.  
  21. ll n,a,b,q,k,del,ans[2];
  22. cin>>n;
  23. M.clear();
  24.  
  25. for(ll i=0;i<n;i++){
  26. cin>>a>>b;
  27. V.pb(mp(a,b));
  28. }
  29.  
  30. cin>>q;
  31.  
  32. while(q--){
  33.  
  34. clr(ans);
  35. M.clear();
  36.  
  37. for(auto x: V) M[x.F] = 0;
  38.  
  39. cin>>k;
  40. while(k--){
  41. cin>>del;
  42. M[del] = 1;
  43. }
  44.  
  45. ll first=-1,second=-1;
  46.  
  47. for(auto x: V){
  48. if(!M[x.F]){
  49.  
  50. if(first == -1){
  51. first = x.F;
  52. second = x.S;
  53. ans[0] = x.F;
  54. ans[1] = x.S;
  55. }
  56. else{
  57. if(x.F!=first){
  58. if(x.S>ans[1]){
  59. ans[0] = x.F;
  60. ans[1] = x.S;
  61. }
  62. }
  63.  
  64. first = x.F;
  65. second = x.S;
  66. }
  67. }
  68. }
  69.  
  70. cout<<ans[0]<<" "<<ans[1]<<endl;
  71.  
  72. }
  73.  
  74.  
  75. return 0;
  76. }
Success #stdin #stdout 0s 3476KB
stdin
6
1 10
2 100
3 1000
1 10000
2 100000
3 1000000
3
1 3
2 2 3
2 1 2
stdout
2 100000
1 10
3 1000