fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. using namespace std;
  5.  
  6. int n;
  7. int a[1003];
  8. int dp[1003];
  9.  
  10. int main() {
  11. freopen("input.txt", "r", stdin);
  12. freopen("output.txt", "w", stdout);
  13.  
  14. cin >> n;
  15. for(int i = 1; i <= n; ++i) {
  16. cin >> a[i];
  17. }
  18. sort(a+1, a+n+1);
  19. for(int i = 1; i <= n; ++i) {
  20. dp[i] = 2e9;
  21. }
  22. for(int i = 2; i <= n; ++i) {
  23. int maximum = a[i];
  24. int minimum = a[i];
  25. for(int j = i-1; j >= 1; --j) {
  26. maximum = max(maximum, a[j]);
  27. minimum = min(minimum, a[j]);
  28. dp[i] = min(dp[i], max(dp[j-1], maximum-minimum));
  29. }
  30. }
  31. cout << dp[n] << endl;
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 4312KB
stdin
Standard input is empty
stdout
Standard output is empty