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 Java (OpenJDK 11.0.6) (judge verdict: Accepted)

import java.io.*;
import java.util.*;

public class Main {

    static class Task {

        private static final int MOD = 998244353;

        private long gcd(long m, long n) {
            if (n == 0) {
                return m;
            }
            return gcd(n, m % n);
        }

        // 快速幂
        public int pow(long x, long n, int mod) {
            long res = 1;
            x %= mod;
            while (n > 0) {
                if ((n & 1) == 1) {
                    res = res * x % mod;
                }

                x = x * x % mod;
                n >>>= 1;
            }
            return (int) res % mod;
        }


        int[] h,to,next,wt,fa;int ct = 0;
        void init(int n ,int m){
            h = new int[n]; Arrays.fill(h,-1);
            to = new int[m*2+2];
            wt = new int[m*2+2];
            next = new int[m*2+2];
            fa = new int[n];Arrays.fill(fa,-1);
            ct = 0;
        }

        void add(int u,int v,int w){
            to[++ct] = v;
            next[ct] = h[u];
            wt[ct] = w;
            h[u] = ct;
        }
        long all = 0;
        PriorityQueue<long[]> q =new PriorityQueue<>((x,y)->{ return Long.compare(y[1]*(y[0]-y[0]/2),x[1]*(x[0]-x[0]/2));});
        public int dfs(int rt,long path){
            int cd = 0;
            int c = 0;
            for(int i=h[rt];i!=-1;i=next[i]){
                if(to[i]==fa[rt]) continue;
                cd++;
                fa[to[i]] = rt;
                int g = dfs(to[i],path+wt[i]);
                q.offer(new long[]{ wt[i] ,(long)g});
                c += g;
            }
            if(cd==0){
                all += path;
                return 1;
            }else{
                return c;
            }


        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {

           oput: for(int i=1;i>0;--i){

               int n  = in.nextInt();
               int k  = in.nextInt();


               long a[]  = new long[n];
               for(int j=0;j<n;++j){
                   a[j] = in.nextLong();
               }
               int lo = 1;
               int hi  =1000000001;
               while(lo<hi){
                   int mid  = lo+hi>>1;
                   long cut =0;
                   for(int j=0;j<n;++j){
                       cut += a[j]/mid;
                       if(a[j]%mid==0&&a[j]/mid>=1){
                           cut--;
                       }
                   }
                   if(cut>k){
                       lo = mid+1;
                   }else{
                       hi = mid;
                   }

               }

            out.println(lo);



            }
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}