Hello 2022
E
New School
Codeforces
2300
原题
← DF →
翻译中…

You have decided to open a new school. You have already found $n$ teachers and $m$ groups of students. The $i$-th group of students consists of $k_i \geq 2$ students. You know age of each teacher and each student. The ages of teachers are $a_1, a_2, \ldots, a_n$ and the ages of students of the $i$-th group are $b_{i, 1}, b_{i, 2}, \ldots, b_{i, k_i}$.

翻译中…

To start lessons you should assign the teacher to each group of students. Such assignment should satisfy the following requirements:

翻译中…
  • To each group exactly one teacher assigned.
  • To each teacher at most $1$ group of students assigned.
  • The average of students' ages in each group doesn't exceed the age of the teacher assigned to this group.
翻译中…

The average of set $x_1, x_2, \ldots, x_k$ of $k$ integers is $\frac{x_1 + x_2 + \ldots + x_k}{k}$.

翻译中…

Recently you have heard that one of the students will refuse to study in your school. After this, the size of one group will decrease by $1$ while all other groups will remain unchanged.

翻译中…

You don't know who will refuse to study. For each student determine if you can start lessons in case of his refusal.

翻译中…

Note, that it is not guaranteed that it is possible to start lessons before any refusal.

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \leq t \leq 1000$) — the number of test cases.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \leq m \leq n \leq 10^5$) — the number of teachers and the number of groups of students.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^5$) — the ages of teachers.

翻译中…

The next $2m$ lines contains descriptions of groups.

翻译中…

The first line of description of group contains a single integer $k_i$ ($2 \leq k_i \leq 10^5$) — the number of students in this group.

翻译中…

The second line of description of group contains $k_i$ integers $b_{i, 1}, b_{i, 2}, \ldots, b_{i, k_i}$ ($1 \leq b_{i, j} \leq 10^5$) — the ages of students of this group.

翻译中…

It is guaranteed that the total sum of $n$ over all test cases doesn't exceed $10^5$ and that the total sum of $k_1 + k_2 + \ldots + k_m$ over all test cases doesn't exceed $2 \cdot 10^5$

翻译中…

Output

翻译中…

For each test case output string of symbols $0$ and $1$ of length $k_1 + k_2 + \ldots + k_m$. The $i$-th symbol of this string should be equals $1$ if it is possible to start lessons in case of the $i$-th student refuse and it should be equals $0$ otherwise.

翻译中…

Students are numbered by integers from $1$ to $k_1 + k_2 + \ldots + k_m$ in the order they appear in the input. Thus, students of the $1$-st group are numbered by integers $1$, $2$, $\ldots$, $k_1$, students of the $2$-nd group are numbered by integers $k_1 + 1$, $k_1 + 2$, $\ldots$, $k_1 + k_2$ and so on.

翻译中…

Note

翻译中…

In the first test case there is one group of students with average age $\frac{25+16+37}{3}=26$ and one teacher with age $30$. There exists only one assignment that allows to start lessons.

翻译中…

If the student with age $16$ will refuse to study, the average age of students in this group will become $\frac{25+37}{2}=31$ so there won't be any assignment that allows to start lessons.

翻译中…

In the second test case it is impossible to start lessons initially. However, if the $3$-rd student with age $111$ will refuse to study, the average ages of groups will become $\frac{4 + 5}{2}=4.5$ and $\frac{11+11}{2} = 11$ correspondingly. Then it is possible to assing the first group to the first teacher and the second group to the third teacher.

翻译中…

样例

Input #1
2
1 1
30
3
25 16 37
4 2
9 12 12 6
2
4 5
3
111 11 11
Output #1
101
00100
InputCopy OutputCopy
题目信息
题号
1621E
所属比赛
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
动态规划
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。