public int woodCut(int[] L, int k) {
        // write your code here
        int max = 0;
        long sum = 0;
        for (int i : L) {
            max = Math.max(i, max);
            sum += i;
        }
        if (sum < k)
            return 0;
        int begin = 1, end = max;
        while (begin + 1 < end) {
            int mid = begin + (end - begin) / 2;
            sum = 0; // calculate how many pieces
            for (int i : L) {
                sum += i / mid;
            }
            if (sum >= k) {
                begin = mid;
            } else {
                end = mid;
            }
        }
        if (end == 2) {
            sum = 0;
            for (int i : L) {
                sum += i / 2;
            }
            if (sum >= k)
                return 2;
        }
        return begin;
    }