QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#1282. 项链

Statistics

Chiaki 有 $n$ 颗美丽的宝石。第 $i$ 颗宝石的颜色为 $c_i$,价值为 $v_i$。

Chiaki 想要选择至少 3 颗宝石制作一条项链,使得相邻的宝石颜色不同。形式化地,设项链中使用的宝石下标为 $a_1, a_2, \dots, a_m$ ($m \ge 3$),按顺时针顺序排列。对于每个 $i$ ($1 \le i \le m$),$c_{a_i}$ 必须与 $c_{a_{i \pmod m + 1}}$ 不同。

Chiaki 想要找到一条价值总和最大的项链:即最大化 $\sum_{i=1}^m v_{a_i}$。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含一个整数 $n$ ($1 \le n \le 2 \cdot 10^5$):宝石的数量。 第二行包含 $n$ 个整数 $c_1, c_2, \dots, c_n$ ($1 \le c_i \le n$),表示每颗宝石的颜色。 第三行包含 $n$ 个整数 $v_1, v_2, \dots, v_n$ ($-10^9 \le v_i \le 10^9$),表示每颗宝石的价值。

保证所有测试数据中 $n$ 的总和不超过 $2 \cdot 10^5$。

输出格式

对于每组测试数据,第一行包含一个整数 $m$ ($m \ge 3$):项链中宝石的数量(注意,你不需要最大化这个数量)。第二行包含 $m$ 个整数 $a_1, a_2, \dots, a_m$ ($1 \le a_i \le n$):按顺时针顺序排列的项链中宝石的下标。如果存在多种可能的答案,输出其中任意一个即可。

如果 Chiaki 无法找到这样的项链,则仅输出一个整数 $-1$。

样例

输入 1

4
4
1 1 1 1
1 2 3 4
4
1 1 2 2
1 2 3 4
8
2 6 5 4 3 1 7 7
-1 4 -1 2 10 -1 3 0
6
5 5 3 3 4 6
5 8 0 -1 -2 -7

输出 1

-1
4
1 3 2 4
4
5 2 4 7
4
3 1 4 2

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.