QOJ.ac

QOJ

Límite de tiempo: 3 s Límite de memoria: 1024 MB Puntuación total: 100

#6104. 建築轟炸

Estadísticas

KAIST 有一排 $N$ 棟建築物,從左到右編號為 $1$ 到 $N$。第 $i$ 棟建築物的高度為 $h_i$。若且唯若第 $i$ 棟建築物左側的所有建築物高度皆嚴格小於 $h_i$ 時,該建築物從左側可見。

你的實驗室位於第 $L$ 棟建築物。由於你最喜歡的數字是 $K$,你希望讓你的實驗室建築物成為從左側可見的建築物中,高度排名第 $K$ 高的建築物。為了達成目標,你可以炸毀其中一些建築物。

例如,假設有 $N = 7$ 棟建築物,高度依序為 $[10, 30, 90, 40, 60, 60, 80]$。你的實驗室位於第 $L = 2$ 棟,你最喜歡的數字是 $K = 3$。在炸毀第 $3$ 棟和第 $7$ 棟建築物後,從左側可見的建築物將變為第 $1, 2, 4, 5$ 棟。此時,你的實驗室便成為從左側可見的建築物中,高度排名第 $3$ 高的建築物,符合你的需求。

請問為了讓你的實驗室建築物成為從左側可見的建築物中,高度排名第 $K$ 高的建築物,最少需要炸毀多少棟建築物?

輸入格式

第一行包含三個以空格分隔的整數 $N, L, K$。 第二行包含 $N$ 個以空格分隔的整數 $h_1, \dots, h_N$。

  • $1 \le L \le N \le 100\,000$
  • $1 \le K \le 10$
  • $1 \le h_i \le 10^9$ ($1 \le i \le N$)

輸出格式

輸出為了讓你的實驗室建築物成為從左側可見的建築物中,高度排名第 $K$ 高的建築物,所需炸毀的最少建築物數量。如果無法達成,則輸出 $-1$。

範例

範例輸入 1

7 2 3
10 30 90 40 60 60 80

範例輸出 1

2

範例輸入 2

3 2 2
30 20 10

範例輸出 2

-1

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#528Editorial Open集训队作业 解题报告 by 卢华睿Qingyu2026-01-02 21:48:09 Download

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.