Levels and Regions

Radewoosh is playing a computer game. There are n levels, numbered 1 through n. Levels are divided into k regions (groups). Each region contains some positive number of consecutive levels.

The game repeats the the following process:

  1. If all regions are beaten then the game ends immediately. Otherwise, the system finds the first region with at least one non-beaten level. Let X denote this region.
  2. The system creates an empty bag for tokens. Each token will represent one level and there may be many tokens representing the same level.
    • For each already beaten level i in the region X, the system adds t i tokens to the bag (tokens representing the i-th level).
    • Let j denote the first non-beaten level in the region X. The system adds t j tokens to the bag.
  3. Finally, the system takes a uniformly random token from the bag and a player starts the level represented by the token. A player spends one hour and beats the level, even if he has already beaten it in the past.

Given nk and values t 1, t 2, …, t n, your task is to split levels into regions. Each level must belong to exactly one region, and each region must contain non-empty consecutive set of levels. What is the minimum possible expected number of hours required to finish the game?

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 200 000, 1 ≤ k ≤ min(50, n)) — the number of levels and the number of regions, respectively.

The second line contains n integers t 1, t 2, …, t n (1 ≤ t i ≤ 100 000).

Output

Print one real number — the minimum possible expected value of the number of hours spent to finish the game if levels are distributed between regions in the optimal way. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.

Namely: let’s assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if  .

Examples

input

4 2
100 3 5 7

output

5.7428571429

input

6 2
1 2 4 8 16 32

output

8.5000000000

Note

In the first sample, we are supposed to split 4 levels into 2 regions. It’s optimal to create the first region with only one level (it must be the first level). Then, the second region must contain other three levels.

In the second sample, it’s optimal to split levels into two regions with 3 levels each.

Solution:

#include<stdio.h>
#include<cassert>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<memory.h>
#include

<map>
#include<set>
#include<queue>
#include 	<list>
#include<sstream>
#include<cstring>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 211111

#define TASK "1"

using namespace std;
typedef pair<int,int> pt;

double sum[N], sd[N], so[N];

//double dp[55][N];

int a[N];
int n, k;

double f[N], f2[N];

double ci[N], cj[N], ki[N], xj[N];

/*double calc(int i, int j) {
double res = sd[j + 1] - sd[i];
res -= sum[i] * (so[j + 1] - so[i]);
//	cout << i << " " << j << " " << res << endl;

	return res;
}*/

double calc2(int i, int j) {
//	cout << i << " " << j << " " << ci[i] + cj[j] + ki[i] * xj[j] << endl;
	return ci[i] + cj[j] + ki[i] * xj[j];
}

int bad(int i, int j, int k) {
	double xr = (ci[j] - ci[k]) / (ki[k] - ki[j]);

	double xl = (ci[i] - ci[j]) / (ki[j] - ki[i]);

	return xr <= xl;
}

int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	cin >> n >> k;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	sum[0] = 0;
	for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];

	sd[0] = 0;
	for (int i = 0; i < n; i++) sd[i + 1] = sd[i] + (sum[i + 1] / 1. / a[i]);

	so[0] = 0;
	for (int i = 0; i < n; i++) so[i + 1] = so[i] + (1. / a[i]);

/*	for (int i = 0; i <= k; i++) for (int j = 0; j <= n; j++) dp[i][j] = 1e50;
	dp[0][0] = 0;

	for (int i = 0; i < k; i++) for (int j = 0; j < n; j++) for (int u = j; u < n; u++)
		dp[i + 1][u + 1] = min(dp[i + 1][u + 1], dp[i][j] + calc(j, u));

	cout << dp[k][n] << endl;*/

	for (int i = 0; i <= n; i++) f[i] = 1e50;
	f[0] = 0;

	for (int it = 0; it < k; it++) {

		for (int i = 0; i < n; i++) {

			cj[i] = sd[i + 1];

			ci[i] = -sd[i] + sum[i] * so[i] + f[i];

			ki[i] = -sum[i];

			xj[i] = so[i + 1];
		}

		vector<int> e;
int u = 0;
for (int i = 0; i < n; i++) {
			while (e.size() >= 2 && bad(e[e.size() - 2], e.back(), i)) e.pop_back();
e.pb(i);
//			f2[i + 1] =1e50;

//			for (int j = 0; j < e.size(); j++) f2[i + 1] = min(f2[i + 1], calc2(e[j], i));
			while (u >= e.size()) u--;

while (u + 1 < e.size() && calc2(e[u], i) >= calc2(e[u + 1], i)) u++;
f2[i + 1] = calc2(e[u], i);
}
for (int i = 0; i <= n; i++) f[i] = f2[i];
	}	

	printf("%.15lf\n", f[n]);

//	assert(fabs(dp[k][n] - f2[n]) < 1e-5);

	return 0;
}