QOJ.ac

QOJ

حد الوقت: 10 s - 20 s حد الذاكرة: 1024 MB مجموع النقاط: 33

#5964. 理发

الإحصائيات

你正在一家时髦的理发店排长队等待理发。店里有 $B$ 名理发师,编号从 $1$ 到 $B$。第 $k$ 位理发师理发一次需要 $M_k$ 分钟,且每位理发师同一时间只能为一名顾客理发。一旦理发师完成理发,他会立即空闲下来去接待下一位顾客。

当理发店营业时,排在队首的顾客总是会选择编号最小的空闲理发师。如果没有理发师空闲,该顾客会一直等待,直到至少有一名理发师空闲为止。

你是队伍中的第 $N$ 位顾客,且理发店刚刚开门。请问哪位理发师会为你理发?

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例,每个测试用例包含两行。第一行包含两个空格分隔的整数 $B$ 和 $N$,分别表示理发师的数量和你在队伍中的位置。队首的顾客编号为 $1$,下一位为 $2$,以此类推。第二行包含 $M_1, M_2, \dots, M_B$。

输出格式

对于每个测试用例,输出一行 "Case #x: y",其中 $x$ 是测试用例编号(从 $1$ 开始),$y$ 是为你理发的理发师编号。

数据范围

$1 \le T \le 100$。 $1 \le N \le 10^9$。

小数据集

$1 \le B \le 5$。 $1 \le M_k \le 25$。

大数据集

$1 \le B \le 1000$。 $1 \le M_k \le 100000$。

样例

输入 1

3
2 4
10 5
3 12
7 7 7
3 8
4 2 1

输出 1

Case #1: 1
Case #2: 3
Case #3: 1

说明

在 Case #1 中,你是队伍中的第四位顾客,理发师 $1$ 和 $2$ 理发分别需要 $10$ 分钟和 $5$ 分钟。当理发店开门时,第一位顾客立即可以选择理发师 $1$ 或 $2$,她会选择编号较小的理发师 $1$。第二位顾客会立即由理发师 $2$ 接待。第三位顾客由于没有空闲的理发师,需要等待。$5$ 分钟后,理发师 $2$ 完成了第二位顾客的理发,并开始接待第三位顾客。$10$ 分钟后,理发师 $1$ 和 $2$ 都完成了工作;此时轮到你,你可以选择理发师 $1$ 或 $2$,你会选择 $1$。

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.