This page is still under construction.

Parts of this page are still being built. What you see may change.

Cow Cars

Time limit1sMemory limit128 MB

Summary
Assign cows to M lanes so each cow's speed minus D times the number of cows ahead in its lane stays at least L, maximizing the number of cows used.
Level

Medium6 of 10

Topics
Greedy, Sorting, Binary search, Implementation
Solved
No attempts yet

Problem

There are NN (1≤N≤500001 \le N \le 50000) cows, numbered 11 through NN, each driving a separate car along a highway. The highway has MM (1≤M≤N1 \le M \le N) lanes, and every cow may drive in any lane. Cow ii has a maximum speed of SiS_i (1≤Si≤10000001 \le S_i \le 1000000) km/h.

To avoid collisions, cow ii slows down by DD (0≤D≤50000 \le D \le 5000) km/h for each cow ahead of it in the same lane. So if KK cows are ahead of cow ii in its lane, that cow travels at max⁡(Si−D⋅K,0)\max(S_i - D \cdot K, 0) km/h. The cows are spaced far enough apart that no crashes occur once they slow down this way.

A minimum-speed law requires every cow on the highway to travel at a speed of at least LL (1≤L≤10000001 \le L \le 1000000) km/h, so some cows may be unable to use the highway. Find the maximum number of cows that can drive on the highway while obeying the minimum-speed law.

Input

  • Line 1: four space-separated integers NN, MM, DD, and LL.
  • Lines 22 to N+1N+1: line i+1i+1 contains a single integer SiS_i, the maximum speed of cow ii.

Output

  • A single integer: the maximum number of cows that can use the highway.

Hint

With three cows, one lane, a per-cow slowdown of 11, and a minimum speed of 55, at most two cows can drive. Put a cow of speed 55 first (it travels at 55) and the cow of speed 77 second (it travels at 7−1=67 - 1 = 6); both meet the minimum speed of 55.

Examples1

  1. Example 1

    Input
    3 1 1 5
    5
    7
    5
    
    Expected output
    2