QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#10923. 暴力破解的终结

الإحصائيات

Chenjb 是第 71 届浙江省大学生程序设计竞赛的题目作者。他设计了一个关于 $n$ 个顶点的图的 NP-Hard 问题,其预期解法是带有分支定界剪枝的 DFS。Chenjb 是一位经验丰富的出题人,他知道约束条件不能太紧,因此他会将时间限制 $t$ 设置为 $3x$,其中 $x$ 是预期解法在最慢测试点上的运行时间。

Chenjb 听说比赛不幸将在 Potato OJ 上举行,而该平台的硬件性能不佳。为了防止 Potato OJ 过载导致比赛失败,Chenjb 计划缩减他题目的输入规模。他已经测试了预期解法和暴力解法在不同 $n$ 值下的运行时间。注意,为简化起见,我们假设解法在测试点上的运行时间仅取决于 $n$ 的值。

请帮助 Chenjb 找到最小的 $n$ 值,使得 $1 \le n \le m$,且暴力解法无法通过该问题。注意,如果时间限制为 $t$,我们假设一个解法能通过当且仅当其在每个测试点上的运行时间小于或等于 $t$。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$ ($1 \le T \le 50$),表示测试数据的组数。

对于每组数据,第一行包含一个整数 $m$ ($1 \le m \le 50$),表示 $n$ 的上限。

第二行包含 $m$ 个整数 $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100, a_i \le a_{i+1}$),其中第 $i$ 个数表示当 $n = i$ 时预期解法的运行时间。

第三行包含 $m$ 个整数 $b_1, b_2, \dots, b_m$ ($1 \le b_i \le 100, b_i \le b_{i+1}$),其中第 $i$ 个数表示当 $n = i$ 时暴力解法的运行时间。

输出格式

对于每组数据,输出一行,包含一个整数,表示最小的 $n$ 值。如果不存在这样的 $n$,则输出 $-1$。

样例

输入 1

2
4
1 2 7 20
2 5 30 40
3
2 3 3
5 7 8

输出 1

3
-1

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.