QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#6318. 魔法钱包

统计

你有一个装有 $X$ 日元的魔法钱包。(日元是日本的货币。)

通过对钱包使用魔法,你可以将钱包里的金额视为一个十进制字符串,并将其中的数字按任意顺序重新排列。例如,如果你的魔法钱包里有 $120$ 日元,你可以使用魔法将钱包里的金额变为以下任意数值:$12$ 日元、$21$ 日元、$102$ 日元、$120$ 日元、$201$ 日元或 $210$ 日元(前导零会被忽略)。

现在,你将按顺序访问 $N$ 家商店。在第 $i$ 家商店($1 \le i \le N$),出售一件价格为 $A_i$ 日元的商品。如果魔法钱包里的金额至少为 $A_i$ 日元,你就可以支付 $A_i$ 日元购买该商品。

你可以在任何时候根据需要多次使用魔法。请问你最多可以购买多少件商品?

输入格式

输入通过标准输入给出,格式如下:

$N \ X$ $A_1 \ A_2 \ \dots \ A_N$

  • 输入中的所有值均为整数。
  • $1 \le N \le 100$
  • $1 \le X < 10^4$
  • $1 \le A_i < 10^4$ ($1 \le i \le N$)

输出格式

输出答案。

样例

输入 1

2 120
142 90

输出 1

2

输入 2

1 119
911

输出 2

1

输入 3

5 1000
900 90 900 9 900

输出 3

3

输入 4

7 1171
6328 2419 8302 7503 1744 8495 1522

输出 4

5

说明

在第一个样例中,你可以通过以下步骤购买两件商品:

  1. 使用魔法将钱包里的金额从 $120$ 日元变为 $201$ 日元。
  2. 在第一家商店购买价格为 $142$ 日元的商品。钱包里的金额变为 $201 - 142 = 59$ 日元。
  3. 使用魔法将钱包里的金额从 $59$ 日元变为 $95$ 日元。
  4. 在第二家商店购买价格为 $90$ 日元的商品。钱包里的金额变为 $95 - 90 = 5$ 日元。

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.