QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 2048 MB Puntuación total: 100

#17327. 我不缺那几分钱

Estadísticas

2025 年 11 月,美国铸造了最后一批便士(一分硬币)。加拿大自 2012 年起就不再铸造便士。

数十亿枚便士仍在流通,但预计便士会随着时间的推移逐渐退出流通。商店预计将继续以分为单位对商品定价,因为信用卡交易是按分结算的。然而,对于现金交易,商店预计会四舍五入到最接近的镍币(五分)。具体来说,如果总购买金额的最后一位数字是 3、4、8 或 9 分,总额将向上取整;如果最后一位是 1、2、6 或 7 分,总额将向下取整。以 0 或 5 分结尾的交易不进行舍入。

你意识到这提供了一个机会。如果你使用现金支付,并适当地重新排列和组合你的购买商品,你或许能为所买的一切少付一点钱!给定你想要购买的每件商品的单价(以分为单位),请确定通过仅使用现金支付并优化组合你的购买商品,与使用信用卡购买所有商品所支付的非舍入总价相比,你最多能节省多少钱。

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 3 \cdot 10^5$),表示你打算购买的商品数量。

下一行包含 $N$ 个以空格分隔的整数 $p_i$ ($1 \le p_i \le 3000$),表示商品的单价(以分为单位)。

输出格式

输出一个整数:信用卡支付的总价(不进行舍入)与通过现金支付并优化组合购买商品所能获得的最低总成本之间的差值。

说明

对于第一个样例,一种最优的商品分组方式是: $\{78, 999, 350\}, \{59, 173, 2995, 350\}, \{882, 298\}, \{1096\}, \{497\}$。

各组的价格分别为 1427、3577、1180、1096、497,因此总差值为: $(1427 + 3577 + 1180 + 1096 + 497) - (1425 + 3575 + 1180 + 1095 + 495) = 7$。

你通过将商品优化组合成几笔现金交易,而不是全部使用信用卡支付,节省了 7 分钱。

样例

样例输入 1

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

样例输出 1

7

样例输入 2

2
199 299

样例输出 2

-2

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.