Codeforces Round 1092 (Unrated, Div. 2, Based on THUPC 2026 — Finals)
A
Course Wishes
Codeforces
900
原题
←B →
翻译中…

qwqkawaii is registering for $n$ ($n\le 50$) courses. In the registration system, he can submit a course wish for each course, which indicates his priority for taking that course.

翻译中…

Course wishes are divided into $k+1$ ($k\le 20$) priority levels, where level $1$ is the highest priority and level $k+1$ is the lowest.

翻译中…

The first $k$ wish levels have capacity limits: for each $1 \le i \le k$, at most $a_i$ courses can be assigned wish level $i$. Note that wish level $k+1$ has no capacity limit.

翻译中…

Initially, the $i$-th course has wish level $b_i$, and it is guaranteed that this initial assignment satisfies all capacity limits. Now qwqkawaii wants to adjust all his courses to wish level $k + 1$. To achieve this, he can apply the following operation at most $1000$ times:

翻译中…
  • Select a course $i$ ($1\le i\le n$), then increase $b_i$ by $1$.
翻译中…

Note that:

翻译中…
  • A course at level $k+1$ cannot be selected;
  • After every single operation, all capacity limits must still be satisfied.
翻译中…

Your task is to construct a valid adjustment sequence with at most $1000$ operations, or report that it is impossible.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 50$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $k$ ($1 \le n \le 50$, $1 \le k \le 20$) — the number of courses and the number of priority levels (excluding the lowest priority level).

翻译中…

The second line contains $k$ integers $a_1, a_2, \ldots, a_k$ ($1 \le a_i \le n$) — the capacity limits of the first $k$ wish levels.

翻译中…

The third line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le k+1$) — the initial wish levels of the courses.

翻译中…

It is guaranteed that the initial assignment satisfies all capacity limits.

翻译中…

Output

翻译中…

For each test case, if it is impossible to reach the target state, print a single integer $-1$.

翻译中…

Otherwise, print the number of operations $m$ ($0 \le m \le 1000$) on the first line of output.

翻译中…

Then print one line with $m$ integers $u_1, u_2, \ldots, u_m$ ($1 \le u_i \le n$), denoting that in the $i$-th operation, you increase the wish level $b_{u_i}$ of course $u_i$ by $1$.

翻译中…

Note

翻译中…

In the first test case, initially, the wish levels are $[1, 2, 2]$. The capacity limits are $a_1=2$ and $a_2=2$. The operations are as follows:

翻译中…
  1. Increase course $2$ to level $3$. Now the wish levels are $[1,3,2]$.
  2. Increase course $1$ to level $2$. Now the wish levels are $[2,3,2]$.
  3. Increase course $3$ to level $3$. Now the wish levels are $[2,3,3]$.
  4. Increase course $1$ to level $3$. Now the wish levels are $[3,3,3]$, which matches the target.
翻译中…

In the second test case, the initial state is already exactly the target state, so no operations are needed.

翻译中…

样例

Input #1
4
3 2
2 2
1 2 2
4 2
2 2
3 3 3 3
1 1
1
1
5 3
1 2 3
1 2 4 2 3
Output #1
4
2 1 3 1
0

1
1
8
2 4 1 2 1 1 5 4
InputCopy OutputCopy
题目信息
题号
2216A
时间限制
1 s
内存限制
256 MB
标签
贪心

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