#K54452. Exact Purchase Problem

    ID: 29756 Type: Default 1000ms 256MiB

Exact Purchase Problem

Exact Purchase Problem

You are given the cost of a cookie \(a\) and the cost of a brownie \(b\). You also have a total of \(x\) dollars and you need to buy exactly \(y\) items (cookies and brownies combined). Determine whether it is possible to purchase exactly \(y\) items such that the total cost is exactly \(x\) dollars.

Mathematically, you need to find non-negative integers \(c\) (number of cookies) and \(d\) (number of brownies) such that:

\[ \begin{aligned} c + d &= y, \\ c \times a + d \times b &= x. \end{aligned} \]

If such a pair \((c, d)\) exists, output YES; otherwise, output NO.

inputFormat

The input consists of a single line containing four space-separated integers:

  • \(a\): the cost of a cookie
  • \(b\): the cost of a brownie
  • \(x\): the total amount of money available
  • \(y\): the total number of items to buy

It is guaranteed that all the numbers are non-negative integers.

outputFormat

Output a single line containing YES if it is possible to buy exactly \(y\) items with exactly \(x\) dollars, or NO if it is not possible.

## sample
2 3 8 4
YES