国王饮水记

国王饮水记

首先我们可以发现一个非常显然的性质: 我们不会合并比\(h_1\)还低的水箱, 所以下文考虑的均是高度高于\(h_1\)的水箱并且水箱是以高度从左到右升序排列的.

还有另一个很显然的性质: 如果操作次数足够大,那我们一定是从左到右依次合并水箱的. 可以证明这一定是最优的.

这个性质启发我们, 如果操作次数不够多, 我们要做的就是将序列划分成若干段以后, 然后依次从左到右依次合并每一段.从而我们可以得到一个\(\text{dp}\),设\(f[i][j]\)表示操作了\(i\)次最后依次操作的一段的结尾为\(j\).转移显然:

\(s[i]\)\(\sum_{j=1}^ih[j]\). \[ \begin{aligned}f[i][j] &= \max_{0 \le k\le j}\left\{\frac{f[i-1][k]+s[j]-s[k]}{j - k + 1}\right\}\end{aligned} \] 复杂度为\(O(n^2kp)\),可以获得\(\text{60}\)分的成绩

整理一下有: \[ \begin{aligned}f[i][j] &= \max_{0 \le k\le j}\left\{\frac{s[j]-(s[k]-f[i-1][k])}{j - (k - 1)}\right\}\end{aligned} \] 把每个决策点\(k\)看成在二维平面上的一个点\((k-1,s[k]-f[i-1][k])\), 我们维护一个关于它的下凸包就可以在凸包上三分啦.复杂度为\(O(nkplogn)\)

然后实际上这个玩意儿是有决策单调性的, 所以每一层的转移可以做到\(O(n)\), 现在复杂度降为\(O(nkp)\). 可以获得\(\text{80}\)分的好成绩.

好像遇到瓶颈了. 继续挖掘性质可以发现:分成的若干段的长度一定是单调不升的.

然后结合\(h_i\)互不相同的这个条件.我们可以推出发现:段长大于一的段只有\(log(\frac{nh}{\Delta})\).

也就是说我们经过若干层转以后, 之后每次的最优决策的段长会收敛为一.然后我们只用\(\text{dp}\)\(log\)层, 后面的就可以直接算答案了.

这样的复杂度为\(O(np\log{nh})\).好像还是有点悬, 实际上\(\text{dp}\)\(log\)层时我们并不需要知道\(\text{dp}\)的精确值, 我们只用记录下来最优转移点即可, 然后\(\text{dp}\)数组用\(\text{double}\)存.最后递归将前\(log\)层的精确值计算出来,再计算后面的部分就好了.

最终复杂度为\(O(np+n\log{nh})\)

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
/*
* 4654.cpp
* This file is part of BZOJ_4654
*
* Copyright (C) 2019 - ViXbob
*
* BZOJ_4654 is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* BZOJ_4654 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with BZOJ_4654. If not, see <http://www.gnu.org/licenses/>.
*/

// Begin at 2019-04-25 19:39:13 - ViXbob

/**
* There is no end though there is a start in space. ---Infinity.
* It has own power, it ruins, and it goes though there is a start also in the star. ---Finite.
* Only the person who was wisdom can read the most foolish one from the history.
* The fish that lives in the sea doesn't know the world in the land.
* It also ruins and goes if they have wisdom.
* It is funnier that man exceeds the speed of light than fish start living in the land.
* It can be said that this is an final ultimatum from the god to the people who can fight.
*
* Steins;Gate
*/
#include <bits/stdc++.h>
#define rep(i, j, k) for(int i = j; i <= k; ++i)
#define dep(i, j, k) for(int i = j; i >= k; --i)
#define SIZE(x) (int)((int)x.size())

typedef long long ll;

using namespace std;

// ---------- decimal lib start ----------

const int PREC = 3600;

class Decimal {
public:
Decimal();
Decimal(const std::string &s);
Decimal(const char *s);
Decimal(int x);
Decimal(long long x);
Decimal(double x);

bool is_zero() const;

// p (p > 0) is the number of digits after the decimal point
std::string to_string(int p) const;
double to_double() const;

friend Decimal operator + (const Decimal &a, const Decimal &b);
friend Decimal operator + (const Decimal &a, int x);
friend Decimal operator + (int x, const Decimal &a);
friend Decimal operator + (const Decimal &a, long long x);
friend Decimal operator + (long long x, const Decimal &a);
friend Decimal operator + (const Decimal &a, double x);
friend Decimal operator + (double x, const Decimal &a);

friend Decimal operator - (const Decimal &a, const Decimal &b);
friend Decimal operator - (const Decimal &a, int x);
friend Decimal operator - (int x, const Decimal &a);
friend Decimal operator - (const Decimal &a, long long x);
friend Decimal operator - (long long x, const Decimal &a);
friend Decimal operator - (const Decimal &a, double x);
friend Decimal operator - (double x, const Decimal &a);

friend Decimal operator * (const Decimal &a, int x);
friend Decimal operator * (int x, const Decimal &a);

friend Decimal operator / (const Decimal &a, int x);

friend bool operator < (const Decimal &a, const Decimal &b);
friend bool operator > (const Decimal &a, const Decimal &b);
friend bool operator <= (const Decimal &a, const Decimal &b);
friend bool operator >= (const Decimal &a, const Decimal &b);
friend bool operator == (const Decimal &a, const Decimal &b);
friend bool operator != (const Decimal &a, const Decimal &b);

Decimal & operator += (int x);
Decimal & operator += (long long x);
Decimal & operator += (double x);
Decimal & operator += (const Decimal &b);

Decimal & operator -= (int x);
Decimal & operator -= (long long x);
Decimal & operator -= (double x);
Decimal & operator -= (const Decimal &b);

Decimal & operator *= (int x);

Decimal & operator /= (int x);

friend Decimal operator - (const Decimal &a);

// These can't be called
friend Decimal operator * (const Decimal &a, double x);
friend Decimal operator * (double x, const Decimal &a);
friend Decimal operator / (const Decimal &a, double x);
Decimal & operator *= (double x);
Decimal & operator /= (double x);

private:
static const int len = PREC / 9 + 1;
static const int mo = 1000000000;

static void append_to_string(std::string &s, long long x);

bool is_neg;
long long integer;
int data[len];

void init_zero();
void init(const char *s);
};

Decimal::Decimal() {
this->init_zero();
}

Decimal::Decimal(const char *s) {
this->init(s);
}

Decimal::Decimal(const std::string &s) {
this->init(s.c_str());
}

Decimal::Decimal(int x) {
this->init_zero();

if (x < 0) {
is_neg = true;
x = -x;
}

integer = x;
}

Decimal::Decimal(long long x) {
this->init_zero();

if (x < 0) {
is_neg = true;
x = -x;
}

integer = x;
}

Decimal::Decimal(double x) {
this->init_zero();

if (x < 0) {
is_neg = true;
x = -x;
}

integer = (long long)x;
x -= integer;

for (int i = 0; i < len; i++) {
x *= mo;
if (x < 0) x = 0;
data[i] = (int)x;
x -= data[i];
}
}

void Decimal::init_zero() {
is_neg = false;
integer = 0;
memset(data, 0, len * sizeof(int));
}

bool Decimal::is_zero() const {
if (integer) return false;
for (int i = 0; i < len; i++) {
if (data[i]) return false;
}
return true;
}

void Decimal::init(const char *s) {
this->init_zero();

is_neg = false;
integer = 0;

// find the first digit or the negative sign
while (*s != 0) {
if (*s == '-') {
is_neg = true;
++s;
break;
} else if (*s >= 48 && *s <= 57) {
break;
}
++s;
}

// read the integer part
while (*s >= 48 && *s <= 57) {
integer = integer * 10 + *s - 48;
++s;
}

// read the decimal part
if (*s == '.') {
int pos = 0;
int x = mo / 10;

++s;
while (pos < len && *s >= 48 && *s <= 57) {
data[pos] += (*s - 48) * x;
++s;
x /= 10;
if (x == 0) {
++pos;
x = mo / 10;
}
}
}
}

void Decimal::append_to_string(std::string &s, long long x) {
if (x == 0) {
s.append(1, 48);
return;
}

char _[30];
int cnt = 0;
while (x) {
_[cnt++] = x % 10;
x /= 10;
}
while (cnt--) {
s.append(1, _[cnt] + 48);
}
}

std::string Decimal::to_string(int p) const {
std::string ret;

if (is_neg && !this->is_zero()) {
ret = "-";
}

append_to_string(ret, this->integer);

ret.append(1, '.');

for (int i = 0; i < len; i++) {
// append data[i] as "%09d"
int x = mo / 10;
int tmp = data[i];
while (x) {
ret.append(1, 48 + tmp / x);
tmp %= x;
x /= 10;
if (--p == 0) {
break;
}
}
if (p == 0) break;
}

if (p > 0) {
ret.append(p, '0');
}

return ret;
}

double Decimal::to_double() const {
double ret = integer;

double k = 1.0;
for (int i = 0; i < len; i++) {
k /= mo;
ret += k * data[i];
}

if (is_neg) {
ret = -ret;
}

return ret;
}

bool operator < (const Decimal &a, const Decimal &b) {
if (a.is_neg != b.is_neg) {
return a.is_neg && (!a.is_zero() || !b.is_zero());
} else if (!a.is_neg) {
// a, b >= 0
if (a.integer != b.integer) {
return a.integer < b.integer;
}
for (int i = 0; i < Decimal::len; i++) {
if (a.data[i] != b.data[i]) {
return a.data[i] < b.data[i];
}
}
return false;
} else {
// a, b <= 0
if (a.integer != b.integer) {
return a.integer > b.integer;
}
for (int i = 0; i < Decimal::len; i++) {
if (a.data[i] != b.data[i]) {
return a.data[i] > b.data[i];
}
}
return false;
}
}

bool operator > (const Decimal &a, const Decimal &b) {
if (a.is_neg != b.is_neg) {
return !a.is_neg && (!a.is_zero() || !b.is_zero());
} else if (!a.is_neg) {
// a, b >= 0
if (a.integer != b.integer) {
return a.integer > b.integer;
}
for (int i = 0; i < Decimal::len; i++) {
if (a.data[i] != b.data[i]) {
return a.data[i] > b.data[i];
}
}
return false;
} else {
// a, b <= 0
if (a.integer != b.integer) {
return a.integer < b.integer;
}
for (int i = 0; i < Decimal::len; i++) {
if (a.data[i] != b.data[i]) {
return a.data[i] < b.data[i];
}
}
return false;
}
}

bool operator <= (const Decimal &a, const Decimal &b) {
if (a.is_neg != b.is_neg) {
return a.is_neg || (a.is_zero() && b.is_zero());
} else if (!a.is_neg) {
// a, b >= 0
if (a.integer != b.integer) {
return a.integer < b.integer;
}
for (int i = 0; i < Decimal::len; i++) {
if (a.data[i] != b.data[i]) {
return a.data[i] < b.data[i];
}
}
return true;
} else {
// a, b <= 0
if (a.integer != b.integer) {
return a.integer > b.integer;
}
for (int i = 0; i < Decimal::len; i++) {
if (a.data[i] != b.data[i]) {
return a.data[i] > b.data[i];
}
}
return true;
}
}

bool operator >= (const Decimal &a, const Decimal &b) {
if (a.is_neg != b.is_neg) {
return !a.is_neg || (a.is_zero() && b.is_zero());
} else if (!a.is_neg) {
// a, b >= 0
if (a.integer != b.integer) {
return a.integer > b.integer;
}
for (int i = 0; i < Decimal::len; i++) {
if (a.data[i] != b.data[i]) {
return a.data[i] > b.data[i];
}
}
return true;
} else {
// a, b <= 0
if (a.integer != b.integer) {
return a.integer < b.integer;
}
for (int i = 0; i < Decimal::len; i++) {
if (a.data[i] != b.data[i]) {
return a.data[i] < b.data[i];
}
}
return true;
}
}

bool operator == (const Decimal &a, const Decimal &b) {
if (a.is_zero() && b.is_zero()) return true;
if (a.is_neg != b.is_neg) return false;
if (a.integer != b.integer) return false;
for (int i = 0; i < Decimal::len; i++) {
if (a.data[i] != b.data[i]) return false;
}
return true;
}

bool operator != (const Decimal &a, const Decimal &b) {
return !(a == b);
}

Decimal & Decimal::operator += (long long x) {
if (!is_neg) {
if (integer + x >= 0) {
integer += x;
} else {
bool last = false;
for (int i = len - 1; i >= 0; i--) {
if (last || data[i]) {
data[i] = mo - data[i] - last;
last = true;
} else {
last = false;
}
}
integer = -x - integer - last;
is_neg = true;
}
} else {
if (integer - x >= 0) {
integer -= x;
} else {
bool last = false;
for (int i = len - 1; i >= 0; i--) {
if (last || data[i]) {
data[i] = mo - data[i] - last;
last = true;
} else {
last = false;
}
}
integer = x - integer - last;
is_neg = false;
}
}
return *this;
}

Decimal & Decimal::operator += (int x) {
return *this += (long long)x;
}

Decimal & Decimal::operator -= (int x) {
return *this += (long long)-x;
}

Decimal & Decimal::operator -= (long long x) {
return *this += -x;
}

Decimal & Decimal::operator /= (int x) {
if (x < 0) {
is_neg ^= 1;
x = -x;
}

int last = integer % x;
integer /= x;

for (int i = 0; i < len; i++) {
long long tmp = 1LL * last * mo + data[i];
data[i] = tmp / x;
last = tmp - 1LL * data[i] * x;
}

if (is_neg && integer == 0) {
int i;
for (i = 0; i < len; i++) {
if (data[i] != 0) {
break;
}
}
if (i == len) {
is_neg = false;
}
}

return *this;
}

Decimal & Decimal::operator *= (int x) {
if (x < 0) {
is_neg ^= 1;
x = -x;
} else if (x == 0) {
init_zero();
return *this;
}

int last = 0;
for (int i = len - 1; i >= 0; i--) {
long long tmp = 1LL * data[i] * x + last;
last = tmp / mo;
data[i] = tmp - 1LL * last * mo;
}
integer = integer * x + last;

return *this;
}

Decimal operator - (const Decimal &a) {
Decimal ret = a;
// -0 = 0
if (!ret.is_neg && ret.integer == 0) {
int i;
for (i = 0; i < Decimal::len; i++) {
if (ret.data[i] != 0) break;
}
if (i < Decimal::len) {
ret.is_neg = true;
}
} else {
ret.is_neg ^= 1;
}
return ret;
}

Decimal operator + (const Decimal &a, int x) {
Decimal ret = a;
return ret += x;
}

Decimal operator + (int x, const Decimal &a) {
Decimal ret = a;
return ret += x;
}

Decimal operator + (const Decimal &a, long long x) {
Decimal ret = a;
return ret += x;
}

Decimal operator + (long long x, const Decimal &a) {
Decimal ret = a;
return ret += x;
}

Decimal operator - (const Decimal &a, int x) {
Decimal ret = a;
return ret -= x;
}

Decimal operator - (int x, const Decimal &a) {
return -(a - x);
}

Decimal operator - (const Decimal &a, long long x) {
Decimal ret = a;
return ret -= x;
}

Decimal operator - (long long x, const Decimal &a) {
return -(a - x);
}

Decimal operator * (const Decimal &a, int x) {
Decimal ret = a;
return ret *= x;
}

Decimal operator * (int x, const Decimal &a) {
Decimal ret = a;
return ret *= x;
}

Decimal operator / (const Decimal &a, int x) {
Decimal ret = a;
return ret /= x;
}

Decimal operator + (const Decimal &a, const Decimal &b) {
if (a.is_neg == b.is_neg) {
Decimal ret = a;
bool last = false;
for (int i = Decimal::len - 1; i >= 0; i--) {
ret.data[i] += b.data[i] + last;
if (ret.data[i] >= Decimal::mo) {
ret.data[i] -= Decimal::mo;
last = true;
} else {
last = false;
}
}
ret.integer += b.integer + last;
return ret;
} else if (!a.is_neg) {
// a - |b|
return a - -b;
} else {
// b - |a|
return b - -a;
}
}

Decimal operator - (const Decimal &a, const Decimal &b) {
if (!a.is_neg && !b.is_neg) {
if (a >= b) {
Decimal ret = a;
bool last = false;
for (int i = Decimal::len - 1; i >= 0; i--) {
ret.data[i] -= b.data[i] + last;
if (ret.data[i] < 0) {
ret.data[i] += Decimal::mo;
last = true;
} else {
last = false;
}
}
ret.integer -= b.integer + last;
return ret;
} else {
Decimal ret = b;
bool last = false;
for (int i = Decimal::len - 1; i >= 0; i--) {
ret.data[i] -= a.data[i] + last;
if (ret.data[i] < 0) {
ret.data[i] += Decimal::mo;
last = true;
} else {
last = false;
}
}
ret.integer -= a.integer + last;
ret.is_neg = true;
return ret;
}
} else if (a.is_neg && b.is_neg) {
// a - b = (-b) - (-a)
return -b - -a;
} else if (a.is_neg) {
// -|a| - b
return -(-a + b);
} else {
// a - -|b|
return a + -b;
}
}

Decimal operator + (const Decimal &a, double x) {
return a + Decimal(x);
}

Decimal operator + (double x, const Decimal &a) {
return Decimal(x) + a;
}

Decimal operator - (const Decimal &a, double x) {
return a - Decimal(x);
}

Decimal operator - (double x, const Decimal &a) {
return Decimal(x) - a;
}

Decimal & Decimal::operator += (double x) {
*this = *this + Decimal(x);
return *this;
}

Decimal & Decimal::operator -= (double x) {
*this = *this - Decimal(x);
return *this;
}

Decimal & Decimal::operator += (const Decimal &b) {
*this = *this + b;
return *this;
}

Decimal & Decimal::operator -= (const Decimal &b) {
*this = *this - b;
return *this;
}

// ---------- decimal lib end ----------


const int maxn = 1e4 + 5;

int n, k, p, U, pre[15][maxn];
double ans, h[maxn], f[10][1 << 10], mn[1 << 10], sum[1 << 10];
double s[maxn], a[maxn];
double F[15][maxn];
Decimal Ans, tmp;

inline int read() {
char ch = getchar(); int u = 0, f = 1;
while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
while(isdigit(ch)) { u = u * 10 + ch - 48; ch = getchar(); } return u * f;
}

Decimal calc(int i, int j) {
if(!i) return h[1];
return (calc(i - 1, pre[i][j]) + s[j] - s[pre[i][j]]) / (j - pre[i][j] + 1);
}

int main() {
// freopen("1.in", "r", stdin);
// freopen("1.out", "w", stdout);
n = read(); k = read(); p = read();
rep(i, 1, n) h[i] = read();
sort(h + 2, h + 1 + n);
if(n <= 10 && k <= 10) {
U = (1 << n) - 1;
rep(S, 1, U) {
mn[S] = 1 << 30;
rep(i, 0, n - 2) if(S >> i & 1) {
mn[S] = min(mn[S], h[i + 2]);
sum[S] += h[i + 2];
}
}
f[0][0] = h[1]; ans = h[1];
rep(i, 0, k - 1) rep(S, 0, U) if(f[i][S] > 0) {
int S1 = ~S & U; ans = max(ans, f[i][S]);
for(int T = S1; T; T = (T - 1) & S1)
f[i + 1][S | T] = max(f[i + 1][S | T], (sum[T] + f[i][S]) / (__builtin_popcount(T) + 1));
}
rep(S, 0, U) ans = max(ans, f[k][S]);
printf("%.10lf\n", ans);
} else if(k == 1) {
double sum = h[1]; int r = n; ans = h[1];
while((sum + h[r]) / (n - r + 2) > sum / (n - r + 1) && r >= 1) {
sum += h[r]; ans = max(ans, sum / (n - r + 2)); r--;
}
printf("%.10lf\n", ans);
} else if(k >= maxn) {
int r = n + 1; Ans = h[1];
while(h[r - 1] > h[1]) r--;
for(int i = r; i <= n; i++) Ans = (Ans + h[i]) / 2;
cout << Ans.to_string(p + 5) << endl;
} else {
int r = n + 1;
while(h[r - 1] > h[1]) r--;
rep(i, r, n) a[i - r + 1] = h[i]; n = n - r + 1;
rep(i, 1, n) s[i] = s[i - 1] + a[i];
int Lim = min(k, 14);
rep(i, 0, n) F[0][i] = h[1];
rep(i, 1, Lim) {
F[i][0] = F[i - 1][0]; int P = 0;
rep(j, 1, n) {
double tmp = 0; int M = P;
rep(v, P, j - 1) {
double now = tmp;
tmp = max(tmp, (F[i - 1][v] + s[j] - s[v]) / (j - v + 1));
if(tmp > now) M = v;
}
if(tmp < F[i - 1][j]) pre[i][j] = j; else pre[i][j] = M;
F[i][j] = max(tmp, F[i - 1][j]); P = M;
}
}
Ans = calc(Lim, n - k + Lim);
rep(i, n - k + Lim + 1, n) Ans = (Ans + a[i]) / 2;
cout << Ans.to_string(p + 5) << endl;
}
return 0;
}
/*
7 7
*/