Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <set>
  6. #include <iomanip>
  7. #include <map>
  8. #include <cmath>
  9. #include <queue>
  10. #include <cstdlib>
  11.  
  12. using namespace std;
  13.  
  14. #define pb push_back
  15. #define ll long long
  16.  
  17. int mode = 1000 * 1000 * 1000 + 7;
  18. int main()
  19. {
  20. ios_base::sync_with_stdio(false);
  21.  
  22. int n;
  23. cin >> n;
  24.  
  25. vector<double> v(n);
  26.  
  27. for(int i = 0; i < n; ++i)
  28. {
  29. cin >> v[i];
  30. }
  31.  
  32. sort(v.begin(), v.end());
  33.  
  34. vector<double> len(n - 1);
  35. vector<double> poss;
  36.  
  37. double mx = 0;
  38. for(int i = 0; i < n - 1; ++i)
  39. {
  40. len[i] = v[i + 1] - v[i];
  41. if(len[i] > mx)
  42. {
  43. poss.clear();
  44. mx = len[i];
  45. poss.pb(i);
  46. }
  47. else if(len[i] == mx)
  48. {
  49. poss.pb(i);
  50. }
  51. }
  52.  
  53. cout << setprecision(1) << fixed;
  54. if(n == 2)
  55. {
  56. cout << len[0] / 2 << endl;
  57. return 0;
  58. }
  59.  
  60. double ans = mx;
  61. for(int i = 0; i < poss.size(); ++i)
  62. {
  63. double ans2 = mx / 2, need = 1;
  64. for(int j = poss[i] - 1; j >= 0; --j)
  65. {
  66. if(ans2 - need < len[j])
  67. {
  68. ans2 += len[j] + need;
  69. }
  70. ++need;
  71. }
  72.  
  73. need = 1;
  74.  
  75. for(int j = poss[i] + 1; j < n - 1; ++j)
  76. {
  77. if(ans2 - need < len[j])
  78. {
  79. ans2 = need + len[j];
  80. }
  81. ++need;
  82. }
  83.  
  84. ans = min(ans, ans2);
  85. }
  86.  
  87. cout << ans << endl;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement