This page is still under construction.

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

Watering

Interview

Time limit1sMemory limit512 MB

Summary
Each day water A consecutive pots adding B moisture, then every pot loses 1; find the latest day the first plant can die with optimal watering.
Level

Medium6 of 10

Topics
Greedy, Sliding window, Prefix sum, Implementation
Solved
No attempts yet

Problem

Rangi the gardener wants to grow catnip, which cats are said to love.

One catnip plant is planted in each of NN flowerpots arranged in a straight line.

Each pot initially holds KK units of moisture, and every day the following happens in order.

  1. Rangi waters AA consecutive pots. The moisture of each watered pot increases by BB.
  2. The moisture of every pot decreases by 1.
  3. The catnip in any pot whose moisture reaches 0 dies.

Write a program that prints the day the first catnip dies when the plants are watered so that all of them stay alive for as long as possible. The first day is day 1.

Input

The first line gives the natural numbers NN, KK, AA, and BB, separated by spaces. (2≤N≤1002 \le N \le 100, 1≤K≤1001 \le K \le 100, 1≤A×B<N1 \le A \times B < N, and AA divides NN)

Output

Print the day the first catnip dies when the plants are watered so that all of them stay alive for as long as possible.

Examples2

  1. Example 1

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

    Input
    2 2 1 1
    
    Expected output
    3