QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 32 MB 总分: 50

#16685. JACK

统计

在著名的扑克牌游戏“21点”(Blackjack)中,目标是使手中的牌的点数之和尽可能大,且不超过 21 点。Mirko 发明了他自己版本的游戏。

在 Mirko 的游戏中,每张牌上都写有一个正整数。玩家会得到一副牌和一个整数 $M$。他必须从这副牌中选择三张牌,使得它们的点数之和在不超过 $M$ 的前提下尽可能接近 $M$。由于给定的牌组中可能有多达 100 张牌,这并不总是那么容易。

请编写一个程序,帮助 Mirko 找到该游戏中最优的可能结果。

输入格式

第一行输入包含两个整数 $N$($3 \le N \le 100$),表示牌的数量,以及 $M$($10 \le M \le 300\,000$),表示我们不能超过的数值。

第二行包含 Mirko 的牌上所写的数字:$N$ 个互不相同的、用空格隔开的正整数,每个数都小于 $100\,000$。

数据保证总是存在三张牌,它们的点数之和不超过 $M$。

输出格式

输出的第一行也是唯一一行,应包含我们能得到的最大可能点数之和。

样例

输入样例 1

5 21
5 6 7 8 9

输出样例 1

21

输入样例 2

10 500
93 181 245 214 315 36 185 138 216 295

输出样例 2

497

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.