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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main implements Runnable {
    static boolean use_n_tests = false;
    static int stack_size = 1 << 20;

    void solve(FastScanner in, PrintWriter out, int testNumber) {
        int n,k;
        n = in.nextInt();
        k = in.nextInt();
        Integer[] a = Array.read(n, in);
        Arrays.sort(a);
        int l = 1;
        int r = a[a.length - 1];
        int ans = -1;
        while (l <= r) {
            int x = (l + r) / 2;
            int cnt = getCnt(a, x);
            if (cnt > k) {
                l = x + 1;
            } else {
                ans = x;
                r = x - 1;
            }
        }
        if (ans == -1) {
            out.println(a[a.length - 1]);
        } else {
            out.println(Math.min(ans, a[a.length - 1]));
        }
    }

    int getCnt(Integer[] a, int x) {
        int cnt = 0;
        for (int i = 0; i < a.length; i++) {
            int ax = a[i];
            if (ax <= x ) {
                continue;
            }
            if (ax % x == 0) {
                cnt += ax / x - 1;
            } else {
                cnt += ax / x;
            }
        }
        return cnt;
    }


    void solve1(FastScanner in, PrintWriter out, int testNumber) {
        int n = in.nextInt();
        String s = in.next();
        int leftWhite = getNextW(s, -1);
        int rightRed = getPrevR(s, s.length());
        int cnt = 0;
        while (leftWhite < rightRed) {
            cnt++;
            leftWhite = getNextW(s, leftWhite);
            rightRed = getPrevR(s, rightRed);
        }
        out.println(cnt);
    }

    int getNextW(String s, int id) {
        for (int i = id + 1; i < s.length(); i++) {
            if (s.charAt(i) == 'W') {
                return i;
            }
        }
        return s.length();
    }

    int getPrevR(String s, int id) {
        for (int i = id - 1; i >= 0; i--) {
            if (s.charAt(i) == 'R') {
                return i;
            }
        }
        return -1;
    }

    // ****************************** template code ***********

    static class Range {
        int l, r;
        public Range(int l, int r) {
            this.l = l;
            this.r = r;
        }
    }
    static class Array {
        static Range[] readRanges(int n, FastScanner in) {
            Range[] result = new Range[n];
            for (int i = 0; i < n; i++) {
                result[i] = new Range(in.nextInt(), in.nextInt());
            }
            return result;
        }
        static public Integer[] read(int n, FastScanner in) {
            Integer[] out = new Integer[n];
            for (int i = 0; i < out.length; i++) {
                out[i] = in.nextInt();
            }
            return out;
        }
    }
    class Graph {
        List<List<Integer>> create(int n) {
            List<List<Integer>> graph = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                graph.add(new ArrayList<>());
            }
            return graph;
        }
    }
    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream io) {
            br = new BufferedReader(new InputStreamReader(io));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

    void run_t_tests() {
        int t = in.nextInt();
        int i = 0;
        while (t-- > 0) {
            solve(in, out, i++);
        }
    }

    void run_one() {
        solve(in, out, -1);
    }

    @Override
    public void run() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        if (use_n_tests) {
            run_t_tests();
        } else {
            run_one();
        }
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(null, new Main(), "", stack_size);
        thread.start();
        thread.join();
    }
}