P7774 [COCI 2009/2010 #2] KUTEVI

Background

This problem is from [\$\texttt{COCI 2009-2010}\ 2^\texttt{nd}\ \texttt{round}\ \text{T3 KUTEVI}\$](https://hsin.hr/coci/archive/2009_2010/contest2_tasks.pdf). The score settings follow the original problem, with a full score of $70$.

Description

You are given $N$ angles (the $i$-th angle is denoted as $a_i$) as initial angles, and also given $M$ angles (the $i$-th angle is denoted as $b_i$) as target angles. For each $b_i$, determine whether it can be obtained by performing addition and subtraction among some of the $a_i$. Note that the same $a_i$ can be used multiple times, or not used at all.

Input Format

The first line contains two positive integers $N, M$. The second line contains $N$ positive integers, where the $i$-th number is $a_i$. The third line contains $M$ positive integers, where the $i$-th number is $b_i$.

Output Format

Output $M$ lines. On the $i$-th line, if $b_i$ can be obtained by performing addition and subtraction among some of the $a_i$, output `YES`; otherwise output `NO`.

Explanation/Hint

### Sample Explanation Explanation for sample $1$: $70^\circ - 30^\circ = 40^\circ$. Explanation for sample $2$: $15 \times 100^\circ = 1500^\circ = 60^\circ$. ### Constraints and Notes $1 \leq N, M \leq 10$, $0 < a_i, b_i < 360$. Translated by ChatGPT 5