QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 1024 MB 总分: 100

#15489. 科利瓦

统计

Colivă 是一种在葬礼上食用的罗马尼亚甜点。它由煮熟的小麦制成,上面撒有糖粉、糖果、椰蓉和其他甜食。

你被要求制作 Colivă,但由于缺乏经验,你把它搞砸了。你的 Colivă 可以看作一个由 $n$ 个整数组成的数组 $a$,其中 $a_i$ 表示索引 $i$ 处的 Colivă 高度。你决定从这个烂摊子中尽可能多地挽救 Colivă。为此,你想选择最长的子数组(数组的连续段),使得该处的 Colivă 看起来很美观。

在每块 Colivă 的顶部都有一颗蓝色糖果。你深知,为了让 Colivă 看起来美观,从左侧看时应该恰好有 $k_1$ 颗可见的蓝色糖果,从右侧看时应该恰好有 $k_2$ 颗可见的蓝色糖果。如果没有其他 Colivă 或糖果遮挡,蓝色糖果就是可见的。更正式地,对于选定的子数组,位于该子数组中索引 $i$ 处的蓝色糖果,如果对于子数组中所有满足 $j < i$ 的索引 $j$ 都有 $a_j < a_i$,则它从左侧可见;如果对于子数组中所有满足 $i < j$ 的索引 $j$ 都有 $a_j < a_i$,则它从右侧可见。

输入格式

第一行包含一个整数 $t$,表示测试用例的数量($1 \le t \le 6$)。接下来是测试用例。

每个测试用例由两行描述。第一行包含三个整数:$n$、$k_1$ 和 $k_2$($1 \le n \le 10^6$,$1 \le k_1, k_2 \le n$)。第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$($1 \le a_i \le n$)。

输出格式

对于每个测试用例,在单独的一行中输出结果。如果无法挽救 Colivă,则输出 -1。否则,输出看起来美观的最长子数组的长度。

样例

输入样例 1

1
12 3 5
1 3 1 2 1 3 4 5 4 3 2 1

输出样例 1

11

说明

在样例中,有两个看起来美观的子数组:$[2, 12]$ 和 $[6, 12]$。其中,子数组 $[2, 12]$ 最长,长度为 $11$。

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.