Under construction

Still being built. Things may change

Drying

Interview

Time limit2sMemory limit64 MB

Summary
Given drying times per cloth that decrease by 1 each minute (or by k for one chosen cloth per minute on a radiator), find the minimum total minutes to dry all clothes, solved via binary search on time.
Level

Medium5 of 10

Topics
Binary search, Greedy
Solved
No attempts yet

Problem

Drying clothes in winter is slow, so Jane speeds it up with a radiator. The radiator is small and can hold only one item at a time.

There are nn freshly washed clothes, and cloth ii holds aia_i units of water. Each minute, the water in every cloth that is not yet dry decreases by 11. The moment a cloth's water reaches 00 it is dry and ready to be packed.

Each minute Jane may also place one cloth on the radiator. During that minute the chosen cloth loses kk units of water instead of the usual 11 (never dropping below 00: if it holds fewer than kk units, its water becomes 00).

Using the radiator as effectively as possible, compute the minimum number of minutes needed until every cloth is dry.

Input

The first line contains a single integer nn (1≤n≤100 0001 \le n \le 100\,000).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n separated by spaces (1≤ai≤1091 \le a_i \le 10^9).

The third line contains a single integer kk (1≤k≤1091 \le k \le 10^9).

Output

Output a single integer: the minimum number of minutes required to dry all the clothes.

Examples5

  1. Example 1

    Input
    3
    2 3 9
    5
    
    Expected output
    3
    
  2. Example 2

    Input
    3
    2 3 6
    5
    
    Expected output
    2
    
  3. Example 3

    Input
    1
    10
    3
    
    Expected output
    4
    
  4. Example 4

    Input
    4
    1 1 1 1
    10
    
    Expected output
    1
    
  5. Example 5

    Input
    5
    1 2 3 4 5
    2
    
    Expected output
    3