欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2216A.Course Wishes
Course Wishes
qwqkawaii is registering for () 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 () priority levels, where level is the highest priority and level is the lowest.
The first wish levels have capacity limits: for each , at most courses can be assigned wish level . Note that wish level has no capacity limit.
Initially, the -th course has wish level , and it is guaranteed that this initial assignment satisfies all capacity limits. Now qwqkawaii wants to adjust all his courses to wish level . To achieve this, he can apply the following operation at most times:
- Select a course (), then increase by .
Note that:
- A course at level 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 operations, or report that it is impossible.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and (, ) — the number of courses and the number of priority levels (excluding the lowest priority level).
The second line contains integers () — the capacity limits of the first wish levels.
The third line contains integers () — 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 .
Otherwise, print the number of operations () on the first line of output.
Then print one line with integers (), denoting that in the -th operation, you increase the wish level of course by .
Note
In the first test case, initially, the wish levels are . The capacity limits are and . The operations are as follows:
- Increase course to level . Now the wish levels are .
- Increase course to level . Now the wish levels are .
- Increase course to level . Now the wish levels are .
- Increase course to level . Now the wish levels are , which matches the target.
In the second test case, the initial state is already exactly the target state, so no operations are needed.
Samples
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
4
2 1 3 1
0
1
1
8
2 4 1 2 1 1 5 4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |