fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. #define endl "\n"
  5. ll P=1e9+7;
  6. ll a[200001];
  7. ll maxi[200001];
  8. ll mini[200001];
  9. ll prefix[200001][6];
  10. ll suffix[200001][6];
  11. void solve(){
  12. ll i,j,k,l,m,n,o,p,q,r,g,s,x,pos,d;
  13. vector<ll> v(6);
  14. for(i=0;i<6;i++){
  15. cin>>v[i];
  16. }
  17. sort(v.begin(),v.end());
  18. cin>>n;
  19. for(j=0;j<6;j++){
  20. prefix[0][j]=LLONG_MAX;
  21. suffix[n+1][j]=0;
  22. }
  23.  
  24. for(i=1;i<=n;i++){
  25. cin>>a[i];
  26. maxi[i]=0;
  27. mini[i]=1e17;
  28. }
  29. sort(a+1,a+n+1);
  30. for(i=1;i<=n;i++){
  31. for(j=0;j<6;j++){
  32. ll note=a[i]-v[j];
  33. for(k=0;k<6;k++){
  34. prefix[i][j]=min(prefix[i-1][k],note);
  35. }
  36.  
  37. }
  38. }
  39.  
  40. ll ans=LLONG_MAX;
  41. for(i=n;i>=1;i--){
  42. for(j=0;j<6;j++){
  43. ll note=a[i]-v[j];
  44. for(k=0;k<6;k++){
  45. suffix[i][j]=max(suffix[i+1][k],note);
  46. }
  47. }
  48. }
  49. for(i=1;i<=n;i++){
  50. for(j=0;j<6;j++){
  51. ans=min(ans,suffix[i][j]-prefix[i][j]);
  52. }
  53. }
  54. cout<<ans<<endl;
  55. }
  56. int main()
  57. {
  58. ios_base::sync_with_stdio(false);
  59. cin.tie(0);
  60. ll t=1;
  61. //cin>>t;
  62. while(t--){
  63. solve();
  64. }
  65. return 0;
  66. }
  67.  
Success #stdin #stdout 0s 4320KB
stdin
1 4 100 10 30 5

6

101 104 105 110 130 200
stdout
0