fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(NULL);
  7.  
  8. int t;
  9. cin >> t;
  10.  
  11. while (t--) {
  12. int n;
  13. cin >> n;
  14.  
  15. vector<double> sticks(n);
  16. for (int i = 0; i < n; i++) {
  17. cin >> sticks[i];
  18. }
  19.  
  20. // Special case: only 2 sticks
  21. if (n == 2) {
  22. cout << fixed << setprecision(6) << min(sticks[0], sticks[1]) << '\n';
  23. continue;
  24. }
  25.  
  26. // Calculate sum of middle sticks
  27. double middleSum = 0;
  28. for (int i = 1; i < n - 1; i++) {
  29. middleSum += sticks[i];
  30. }
  31.  
  32. // For n >= 3: max height = min(first + middle/2, last + middle/2)
  33. double maxHeight = min(sticks[0] + middleSum / 2.0, sticks[n-1] + middleSum / 2.0);
  34.  
  35. cout << fixed << setprecision(6) << maxHeight << '\n';
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
5
1 2 4 2 3
3
1 4 1
2
4 4
6
1 6 13 4 100 2
3
1 2 3
stdout
5.000000
3.000000
4.000000
62.500000
2.000000