QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#6104. 建物の爆破

Statistics

KAISTには、$1$ から $N$ まで左から右に番号が振られた $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$ $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.