P27288 [AtCoder] One Yen Coin
省选
题目描述

Problem Description

The coins currently used in KUPC country are the same as in Japan: $500$, $100$, $50$, $10$, $5$, and $1$ yen coins, totaling 6 types.

The only shop in KUPC country sells $N$ items, and the price of the $i$-th item is $A_i$ yen. You have $X$ yen with you, with the minimum number of coins.

You can now shop freely in the store. In your shopping, you can repeat the checkout process defined below as many times as you like.

  • Checkout refers to selecting some items and paying an amount of money that is at least the total price of the selected items to purchase them.
  • At this time, the difference between the paid money and the total price of the selected items is returned as change, with the minimum number of coins.
  • Since each item is unique, you cannot purchase the same item multiple times throughout your shopping.

You like $1$ yen coins and want to collect as many as possible. Find the maximum number of $1$ yen coins you can have after finishing your shopping.

Input Format

The input is given from the standard input in the following format:

$N$ $X$ $A_1$ $A_2$ $\ldots$ $A_N$

Output Format

Output the maximum number of $1$ yen coins you can have after finishing your shopping in one line.

Sample Input and Output

Sample Input #1

5 57
27 18 31 9 14

Sample Output #1

8

Sample Input #2

4 50
11 11 11 11

Sample Output #2

12

Notes/Hints

Constraints

  • $1 \leq N \leq 10^5$
  • $1 \leq X \leq 10^{14}$
  • $1 \leq A_i \leq 10^9$
  • All inputs are integers.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 57 27 18 31 9 14
样例输出
8