QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#6135. 书

統計

DreamGrid 昨天去了书店。书店里总共有 $n$ 本书。因为 DreamGrid 非常富有,他按照以下策略购买书籍:

  • 按顺序从第 1 本书检查到第 $n$ 本书。
  • 对于当前检查的每一本书,如果 DreamGrid 有足够的钱(不少于书的价格),他就会买下这本书,并且他的钱会减少书的价格。
  • 如果他手里的钱少于当前检查的书的价格,他就会跳过这本书。

BaoBao 对 DreamGrid 有多富有感到好奇。你需要告诉他 DreamGrid 在买书之前所携带的钱的最大可能金额,这是一个非负整数。他只知道 $n$ 本书的价格以及 DreamGrid 总共购买的书的数量,记为 $m$。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含两个整数 $n$ 和 $m$ ($1 \le n \le 10^5, 0 \le m \le n$),分别表示书店里的书的数量和 DreamGrid 总共购买的书的数量。

第二行包含 $n$ 个非负整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$),其中 $a_i$ 表示 DreamGrid 检查的第 $i$ 本书的价格。

保证所有测试数据中 $n$ 的总和不超过 $10^6$。

输出格式

对于每组测试数据,输出一行。

如果对于任何初始金额都无法买到 $m$ 本书,输出 “Impossible”(不含引号)。 如果 DreamGrid 可以携带无限多的钱,输出 “Richman”(不含引号)。 在其他情况下,输出一个非负整数,表示他可能携带的最大金额。

样例

输入 1

4
4 2
1 2 4 8
4 0
100 99 98 97
2 2
10000 10000
5 3
0 0 0 0 1

输出 1

6
96
Richman
Impossible

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.