CF1621E.New School
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ki≥2 students. You know age of each teacher and each student. The ages of teachers are a1,a2,…,an and the ages of students of the i-th group are bi,1,bi,2,…,bi,ki.
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 x1,x2,…,xk of k integers is kx1+x2+…+xk.
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.
你决定创办一所新学校。你已经找到了 n 名教师和 m 个学生小组。第 i 个学生小组包含 ki≥2 名学生。你知道每位教师和每位学生的年龄:教师的年龄为 a1,a2,…,an,第 i 个学生小组中学生的年龄为 bi,1,bi,2,…,bi,ki。
为了开始授课,你需要为每个学生小组分配一名教师。该分配需满足以下条件:
- 每个学生小组恰好分配一名教师;
- 每名教师至多分配一个学生小组;
- 每个学生小组中学生的平均年龄不超过分配给该小组的教师的年龄。
集合 x1,x2,…,xk(含 k 个整数)的平均值为 kx1+x2+…+xk。
最近你听说将有一名学生拒绝在你的学校就读。此后,某个学生小组的规模将减少 1,其余所有小组保持不变。
你并不知道哪位学生会拒绝就读。对每一位学生,请判断:若该学生拒绝就读,你是否仍能正常开始授课。
注意:在任何学生拒绝就读之前,不一定总能保证可以开始授课。
输入格式
The first line contains a single integer t (1≤t≤1000) — the number of test cases.
The first line of each test case contains two integers n and m (1≤m≤n≤105) — the number of teachers and the number of groups of students.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤105) — the ages of teachers.
The next 2m lines contains descriptions of groups.
The first line of description of group contains a single integer ki (2≤ki≤105) — the number of students in this group.
The second line of description of group contains ki integers bi,1,bi,2,…,bi,ki (1≤bi,j≤105) — the ages of students of this group.
It is guaranteed that the total sum of n over all test cases doesn't exceed 105 and that the total sum of k1+k2+…+km over all test cases doesn't exceed 2⋅105
第一行包含一个整数 t(1≤t≤1000)—— 测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 m(1≤m≤n≤105)—— 教师人数和学生组数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤105)—— 教师们的年龄。
接下来的 2m 行描述各学生组。
每组描述的第一行包含一个整数 ki(2≤ki≤105)—— 该组的学生人数。
每组描述的第二行包含 ki 个整数 bi,1,bi,2,…,bi,ki(1≤bi,j≤105)—— 该组学生的年龄。
保证所有测试用例中 n 的总和不超过 105,且所有测试用例中 k1+k2+…+km 的总和不超过 2⋅105。
输出格式
For each test case output string of symbols 0 and 1 of length k1+k2+…+km. 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 k1+k2+…+km in the order they appear in the input. Thus, students of the 1-st group are numbered by integers 1, 2, …, k1, students of the 2-nd group are numbered by integers k1+1, k1+2, …, k1+k2 and so on.
对每个测试用例,输出一个由符号 0 和 1 组成的长度为 k1+k2+…+km 的字符串。该字符串的第 i 个符号应为 1,当且仅当第 i 位学生拒绝参加时仍可正常开始授课;否则应为 0。
学生按其在输入中出现的顺序编号,编号为整数 1 至 k1+k2+…+km。因此,第 1 组的学生编号为 1,2,…,k1,第 2 组的学生编号为 k1+1,k1+2,…,k1+k2,依此类推。
输入输出样例
输入#1
2 1 1 30 3 25 16 37 4 2 9 12 12 6 2 4 5 3 111 11 11
输出#1
101 00100
说明/提示
In the first test case there is one group of students with average age 325+16+37=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 225+37=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 24+5=4.5 and 211+11=11 correspondingly. Then it is possible to assing the first group to the first teacher and the second group to the third teacher.
在第一个测试用例中,有一组学生,其平均年龄为 325+16+37=26,还有一位年龄为 30 的教师。此时仅存在一种分配方案,使得课程可以开始。
若年龄为 16 的学生拒绝学习,则该组学生的平均年龄变为 225+37=31,此时将不存在任何允许课程开始的分配方案。
在第二个测试用例中,初始状态下无法开始课程。然而,若第 3 位年龄为 111 的学生拒绝学习,则各组学生的平均年龄将分别变为 24+5=4.5 和 211+11=11。此时可将第一组学生分配给第一位教师,第二组学生分配给第三位教师。
输入解题思路,AI测评打分。不知道怎么写?