logo AlgoBeat OnlineJudge
登录 注册

#215945. [ICPC 2026 NAC] I Don' t Miss Pennies

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

In November 2025, the United States minted its last pennies (one-cent coins). Canada has not minted pennies since 2012.

Billions of pennies remain in circulation, but pennies are expected to fade from circulation over time. Stores are expected to continue to price items to the cent, as credit card transactions are processed to the cent. However, for cash transactions, stores are expected to round to the nearest nickel (five cents). Specifically, if the final digit of a total purchase ends in , , or cents, the total will be rounded up; if it ends in , , or cents, it will be rounded down. Transactions ending in or cents are not rounded.

You realize that this provides an opportunity. If you pay cash and rearrange and group your purchases appropriately, you may be able to pay slightly less for everything you buy! Given the prices of the individual items you wish to buy in cents, determine the maximum amount you could save by paying solely in cash and rearranging and grouping your purchases optimally, compared to the non-rounded total price you would pay if you bought all of the items with a credit card.

输入格式

The first line of input contains a single integer (), the number of items you intend to purchase.

The next line contains space-separated integers (), the prices of the items in cents.

输出格式

Print a single integer: the difference between the total credit card price without rounding and the lowest total cost that can be obtained by paying cash and grouping purchases optimally.

样例

样例输入 1

11
78 59 90 999 173 882 1096 2995 298 497 350

样例输出 1

7

样例输入 2

2
199 299

样例输出 2

-2

数据范围与提示

For the first sample, one optimal grouping of items is

The prices of each group are, respectively, and thus the total difference is

You save cents by optimally grouping the items into several cash transactions instead of paying for everything with a credit card.