Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. int a,b,sum,i,j;
  8. while(t--)
  9. {
  10. cin>>a>>b>>sum;
  11. int x[a],y[b];
  12. for(i=0;i<a;i++) cin>>x[i];
  13. for(i=0;i<b;i++) cin>>y[i];
  14. sort(x,x+a);
  15. sort(y,y+b);
  16. int count=0,c=0,d=1;
  17. for(i=0;i<a;i++)
  18. {
  19. for(j=0;j<b;j++)
  20. {
  21. if((x[i]+y[j])== sum)
  22. {
  23. count++;
  24. if(count>1)
  25. {
  26. cout<<", ";
  27. }
  28. cout<<x[i]<<" "<<y[j];
  29. }
  30. }
  31. }
  32. if(count==0) cout<<-1<<endl;
  33. cout<<endl;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement