QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#3427. 摆脱硬币

统计

当 Per 住在纽约时,他无法像在瑞典那样频繁地使用借记卡。他不得不随身携带现金,钱包因为装满了硬币而变得很沉。有一次,他在一家糖果店买了数公斤糖果,他想尽可能多地花掉手中的硬币,但又不知道如何在不找零的情况下做到这一点。

任务

给定 Per 需要支付的价格 $P$。同时给定他钱包中 1 美分、5 美分、10 美分和 25 美分硬币的数量。他没有纸币。请找出他在不找零的情况下支付价格 $P$ 时,最多可以使用多少枚硬币。

输入格式

输入的第一行包含一个整数 $P$ ($1 \le P \le 100\,000\,000$),即 Per 需要支付的价格。第二行包含 4 个空格分隔的整数 $N_1, N_5, N_{10}, N_{25}$ ($0 \le N_1, N_5, N_{10}, N_{25} \le 100\,000\,000$),分别表示 Per 钱包中 1 美分、5 美分、10 美分和 25 美分硬币的数量。

输出格式

如果 Per 无法在不找零的情况下正好支付 $P$,则输出 Impossible。否则,输出 Per 在支付价格 $P$ 时最多可以使用的硬币数量。

样例

样例输入 1

13
3 2 1 1

样例输出 1

5

样例输入 2

13
2 2 1 1

样例输出 2

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.