QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 2048 MB 총점: 100

#16039. 郊游

통계

来自维基百科,根据知识共享许可协议发布,作者 Tom Page

为老年人组织一次团体旅行可能是一项艰巨的任务……这在很大程度上是因为有些挑剔的参与者,他们每个人都只有在另一位参与者也去的情况下才愿意出行。

经过一番努力,你从每位参与者那里收集到了一个编号,表示除非该编号对应的参与者也参加,否则该参与者将拒绝参加这次远足——要求较低的参与者只需给出他们自己的编号。这本来很容易解决(把他们全部送去即可),但你在旅行中使用的巴士只有固定数量的座位。

给定所有参与者的偏好,求能够参加旅行的最大参与者人数。

输入格式

输入的第一行包含两个整数 $n$ 和 $k$($1 \le k \le n \le 1\,000$),其中 $n$ 表示参与者的总人数,$k$ 表示巴士上的座位数。

第二行包含 $n$ 个整数 $x_i$(对于 $i = 1, 2, \dots, n$),其中 $1 \le x_i \le n$。$x_i$ 的含义是:除非第 $x_i$ 个参与者也参加,否则第 $i$ 个参与者将拒绝参加这次远足。

输出格式

输出一个整数:在满足所有参与者的偏好且不超过巴士容量的前提下,能够参加远足的最大参与者人数。

样例

输入样例 1

4 4
1 2 3 4

输出样例 1

4

输入样例 2

12 3
2 3 4 5 6 7 4 7 8 8 12 12

输出样例 2

2

输入样例 3

5 4
2 3 1 5 4

输出样例 3

3

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.