#K71397. Taco Sort Challenge

    ID: 33522 Type: Default 1000ms 256MiB

Taco Sort Challenge

Taco Sort Challenge

You are given an array of n integers and a list of k multipliers. Your task is to determine whether it is possible to obtain a non-decreasing array by choosing, for each element, one multiplier from the given list and multiplying the element by that multiplier.

Formally, given an array \(a_1, a_2, \ldots, a_n\) and multipliers \(m_1, m_2, \ldots, m_k\), you need to decide if there exists a sequence \(c_1, c_2, \ldots, c_n\) where each \(c_i\) is one of the multipliers such that the new array \(b\) given by \(b_i = a_i \times c_i\) is sorted in non-decreasing order, i.e., \[ b_1 \leq b_2 \leq \cdots \leq b_n. \]

If such an assignment exists, print YES; otherwise print NO.

inputFormat

The input is given in the following format via standard input:

  • The first line contains two integers n and k separated by a space.
  • The second line contains n space-separated integers representing the array.
  • The third line contains k space-separated integers representing the available multipliers.

outputFormat

Output a single line containing YES if there exists an assignment of multipliers that sorts the array in non-decreasing order, otherwise output NO.

## sample
5 2
1 2 3 4 5
2 3
YES