fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <vector>
  5. using namespace std;
  6. #define SZ(a) (int)(a).size()
  7. typedef long long ll;
  8.  
  9. #include <ext/pb_ds/assoc_container.hpp> // Common file
  10. #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
  11.  
  12. using namespace __gnu_pbds;
  13.  
  14. typedef tree<double, null_type, greater<double>, rb_tree_tag, tree_order_statistics_node_update> oset;
  15.  
  16. const auto eps = 1e-3;
  17. const auto mlpy = 10;
  18. int n, l, r;
  19. ll m;
  20. vector<double> a;
  21. int nr;
  22.  
  23. bool f(double mean) {
  24. auto k = 0ll;
  25. vector<double> b(n+1);
  26. b[0] = 0;
  27. for (auto i = 1; i <= n; i++) {
  28. b[i] = b[i-1]+a[i-1]-mean;
  29. }
  30. oset o;
  31. for (auto i = l; i <= n; i++) {
  32. auto s = b[i-l];
  33. while (!o.insert(s).second) {
  34. s = b[i-l]+(double)(rand()%nr)/nr*eps;
  35. }
  36. if (i >= r) {
  37. o.erase(o.lower_bound(b[i-r]));
  38. }
  39. k += o.order_of_key(b[i]+eps);
  40. if (k >= m) {
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46.  
  47. double bsearch(double lo, double up) {
  48. auto mi = (lo+up)/2;
  49. if (up-lo < eps) {
  50. return mi;
  51. }
  52. if (f(mi)) {
  53. bsearch(lo, mi);
  54. }
  55. else {
  56. bsearch(mi, up);
  57. }
  58. }
  59.  
  60. int main() {
  61. cin.sync_with_stdio(false);
  62. cin >> n >> l >> r >> m;
  63. r++;
  64. nr = n*mlpy;
  65. a.resize(n);
  66. for (auto i = 0; i < n; i++) {
  67. cin >> a[i];
  68. }
  69. auto ans = bsearch(1.0, 1e6);
  70. printf("%f\n", ans);
  71. return 0;
  72. }
  73.  
Success #stdin #stdout 0s 16072KB
stdin
Standard input is empty
stdout
1.000466