Under construction

Still being built. Things may change

Sanghyeon's Math Study Plan

Interview

Time limit1sMemory limit1024 MB

Summary
Find the smallest constant daily problem count x so that the total favorability over N days, where each day's value is piecewise linear in x, is at least L.
Level

Medium4 of 10

Topics
Binary search, Array
Solved
No attempts yet

Problem

A teacher at KSA likes students who study math hard, so the teacher has decided to make students study a lot of math over the next NN days. The teacher wants a student to solve AiA_i math problems on day ii. The teacher's favorability toward a student depends on how many problems the student solved that day. If a student solved xx problems on day ii, the favorability increases by the following amount.

fi(x)={xif x≥Ai,2(x−Ai)if x<Aif_i(x) = \begin{cases} x & \text{if } x \ge A_i, \\ 2(x - A_i) & \text{if } x < A_i \end{cases}

Sanghyeon wants a regular routine, so he decides to solve the same number of math problems every day for NN days. At first, the teacher's favorability toward Sanghyeon is 00. Sanghyeon wants a favorability of at least LL after NN days. Find the minimum number of problems he must solve per day.

Input

The first line contains an integer NN (1≤N≤1051 \le N \le 10^5). The second line contains NN integers A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N separated by spaces (1≤Ai≤1041 \le A_i \le 10^4). The third line contains an integer LL (1≤L≤1091 \le L \le 10^9).

Output

Print the minimum number of math problems Sanghyeon must solve per day.

Examples1

  1. Example 1

    Input
    2
    5 4
    6
    
    Expected output
    5