Problem:
Score : 500 points

Problem Statement

We have N logs of lengths A_1,A_2,\cdots A_N.

We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.

Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 10^9

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_N

Output

Print an integer representing the answer.

Sample Input 1

2 3
7 9

Sample Output 1

4

First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.

Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.

Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.

In this case, the longest length of a log will be 3.5, which is the shortest possible result. After rounding up to an integer, the output should be 4.

Sample Input 2

3 0
3 4 5

Sample Output 2

5

Sample Input 3

10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202

Sample Output 3

292638192

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define EPS 1e-5
using namespace std;

LL T,n,i,j,k,x,y,z;
LL a[N],b[N];

LL l,r,mid,ans;

IL bool Check(LL x){
	reg LL i=0,s=0,p=0;
	for (i=1;i<=n;i++){
		if (a[i]<=x)	continue;
		p=(LL)(a[i]/x);
		if (a[i]>p*x)	s+=p;
		else s+=p-1;
	}
	if (s<=k)	return 1;
	else return 0;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	scanf("%lld%lld",&n,&k);
	for (i=1;i<=n;i++)	scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	for (i=1;i<=n;i++)	a[i]*=2;
	for (i=1;i<=n;i++)	a[0]+=a[i];
	if (a[0]<k)	{
		cout<<"0"<<endl;
		return 0;
	}
	if (!k){
		cout<<a[n]/2<<endl;
		return 0;
	}
	l=0;	r=a[n]*2;
	while (l<=r){
		mid=(l+r)>>1;
		if (Check(mid))	ans=mid,r=mid-1;
		else l=mid+1;
	}
	while (ans>1 && Check(ans-1))	ans--;
	while (!Check(ans))	ans++;
	if (ans&1)	cout<<(ans+1)/2<<endl;
	else cout<<ans/2<<endl;
	return 0;
}