fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long int
  3. #define mod 1000000007
  4.  
  5. using namespace std;
  6. int main()
  7. {
  8. std::ios::sync_with_stdio(false);
  9. #ifndef ONLINE_JUDGE
  10. freopen("input.txt", "r", stdin);
  11. freopen("output.txt", "w", stdout);
  12. freopen("error.txt", "w", stderr);
  13. #endif
  14. int T;
  15. cin >> T;
  16. int n;
  17. while (T--)
  18. {
  19. cin >> n;
  20. ll arr[n];
  21. ll copg[n], cops[n];
  22. for (int i = 0; i < n; ++i)
  23. {
  24. cin >> arr[i];
  25. arr[i] %= mod;
  26. }
  27. copy(arr, arr + n, copg);
  28. copy(arr, arr + n, cops);
  29. sort(copg, copg + n, greater<ll>());
  30. sort(cops, cops + n);
  31. ll copmin = (copg[0] - copg[2]) % mod;
  32. ll compsmin = (cops[2] - cops[0]) % mod;
  33. ll mi = min(compsmin, copmin) % mod;
  34. cout << mi << endl;
  35.  
  36. }
  37. }
  38.  
Success #stdin #stdout 0.01s 5444KB
stdin
4
3
1 2 3
4
7 3 7 3
5
3 4 2 1 1
8
3 1 4 1 5 9 2 6
stdout
2
4
1
1