fork download
  1. /*mahendra25---PVPSIT-IT
  2. IT ONLY HAS TO WORK ONCE!
  3. */
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define pi 3.14159265358979323846264338327950
  7. const int N=1e6+20,mod=(int)(1e9)+7;
  8. #define pb push_back
  9. #define ull unsigned long long
  10. #define ll long long
  11. int main(){
  12. // freopen("input.txt", "r", stdin);
  13. // freopen("output.txt", "w", stdout);
  14. int T;
  15. scanf("%d",&T);
  16. while(T--){
  17. int a,b;
  18. cin>>a;
  19. int arr[a];
  20. for(int i=0;i<a;i++)
  21. cin>>arr[i];
  22. cin>>b;
  23. int arr1[b],diff=1e5;
  24. for(int i=0;i<b;i++)
  25. cin>>arr1[i];
  26. for(int i=0;i<a;i++)
  27. for(int j=0;j<b;j++)
  28. if(abs(arr[i]-arr1[j])<diff)
  29. diff=abs(arr[i]-arr1[j]);
  30. cout<<diff<<endl;
  31. }
  32. return(0);
  33. }
Success #stdin #stdout 0s 16064KB
stdin
2
8 1 3 5 7 9 7 3 1
8 2 4 6 8 10 8 6 2
8 2 3 5 10 9 3 2 1
7 1 2 6 12 13 3 2
stdout
1
0