fork(1) download
  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include<ctime>
  7. #include<vector>
  8. #include<queue>
  9. #include<stack>
  10. #include<map>
  11. using namespace std;
  12. #define FOR(i,s,e) for (int i=s;i<e;i++)
  13. #define FOE(i,s,e) for (int i=s;i<=e;i++)
  14. #define FOD(i,s,e) for (int i=s;i>=e;i--)
  15. #define SET(a,e) memset(a,e,sizeof(a))
  16. #define LL long long
  17. #define LD long double
  18. #define pb push_back
  19. #define x first
  20. #define y second
  21. #define PII pair<int,int>
  22. #define PLI pair<LL,int>
  23.  
  24. int n,a[100055];
  25. bool v[100055];
  26.  
  27. int best(int x) {
  28.  
  29. if (x == n-1) {
  30. int p = 0;
  31. FOR(i,0,n) if (!v[i]) {
  32. p = a[i];
  33. break;
  34. }
  35. FOD(i,n-1,0) if (!v[i])
  36. return a[i] - p;
  37. }
  38.  
  39. if (x & 1) {
  40. int ret = 1000000000;
  41. FOR(i,0,n) if (!v[i]) {
  42. v[i] = 1;
  43. ret = min(ret,best(x+1));
  44. v[i] = 0;
  45. }
  46. return ret;
  47. }
  48.  
  49. else {
  50. int ret = 0;
  51. FOR(i,0,n) if (!v[i]) {
  52. v[i] = 1;
  53. ret = max(ret,best(x+1));
  54. v[i] = 0;
  55. }
  56. return ret;
  57. }
  58.  
  59. }
  60.  
  61. int main () {
  62.  
  63. scanf("%d",&n);
  64.  
  65. FOR(i,0,n) scanf("%d",a+i);
  66.  
  67. sort(a,a+n);
  68.  
  69. printf("%d\n",best(1));
  70.  
  71. return 0;
  72. }
Success #stdin #stdout 0s 3904KB
stdin
5
1 7 100 130 131
stdout
6