Universal Cup Judging System

Universal Cup

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100 Difficulty: [show] Hackable ✓
Statistics

Kevin 和 Little Cyan Fish 参加了中国凸多边形竞赛决赛(CCPC Final)。在线评测系统有一个名为“最后成功者”(Last Success)的统计数据,表示当前最后一位成功解出一道题目的人。

比赛持续 $m$ 秒,包含 $n$ 道题目。Little Cyan Fish 得知 Kevin 将在比赛开始后的 $a_1, a_2, \dots, a_n$ 秒分别解出一道题。而 Little Cyan Fish 完成每道题分别需要 $b_1, b_2, \dots, b_n$ 秒。Little Cyan Fish 想要制定一个策略(即解题顺序以及何时提交),使得他作为“最后成功者”的时间总长最大化。

请注意:

  • 完成一道题目后,Little Cyan Fish 不需要立即提交。他可以选择在此期间先去解决另一道题目。
  • 提交和其他操作不消耗时间,这允许 Little Cyan Fish 在完成另一道题的同时提交题目。
  • 如果 Little Cyan Fish 和 Kevin 在同一时间提交答案,“最后成功者”归属于 Little Cyan Fish。
  • 在比赛开始时以及在任何提交之前,“最后成功者”为空。

输入格式

输入包含多个测试用例。输入的第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试用例的数量。

对于每个测试用例,第一行包含两个整数 $n$ 和 $m$ ($1 \le n \le 10^5, 1 \le m \le 10^9$)。

下一行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le m$)。保证对于所有 $1 \le i < n$,都有 $a_i < a_{i+1}$。

下一行包含 $n$ 个整数 $b_1, b_2, \dots, b_n$ ($1 \le b_i \le m$)。

保证所有测试用例的 $n$ 之和不超过 $10^5$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示答案。

样例

输入 1

3
3 10
1 5 9
1 2 3
3 10
1 5 9
1 1 4
3 10
1 5 9
1 5 10

输出 1

9
9
7

说明

对于第一个测试用例,Little Cyan Fish 可以:

  • 从第 0 秒开始,在第 1 秒完成第一道题并立即提交;
  • 从第 1 秒开始,在第 3 秒完成第二道题,并等待至第 5 秒提交;
  • 从第 4 秒开始,在第 7 秒完成第三道题,并等待至第 9 秒提交;

从第 1 秒开始,“最后成功者”为 Little Cyan Fish,因此答案为 $10 - 1 = 9$。

对于第三个测试用例,Little Cyan Fish 可以:

  • 从第 0 秒开始,在第 1 秒完成第一道题并立即提交;
  • 从第 1 秒开始,在第 6 秒完成第二道题并立即提交;
  • 放弃无法完成的第三道题。

从第 1 秒到第 5 秒,以及从第 6 秒到第 9 秒,“最后成功者”为 Little Cyan Fish,因此答案为 $(5 - 1) + (9 - 6) = 7$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.