QOJ.ac

QOJ

実行時間制限: 3.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#17888. 사탕 배달

統計

喜欢糖果的小石欢在家里放了一个装有 $N$ 个糖果的袋子。袋子里有两种糖果:小糖果的重量为 3g,大糖果的重量为 5g。聪明的小石欢计算了袋子里所有糖果的甜度 $s_i$。$s_i$ 是一个正整数,其值越大,糖果就越甜。

为了参加 shake! 2019 比赛,正在收拾行李的小石欢想要带尽可能多的甜糖果,以便在比赛期间补充糖分。然而,虚弱的小石欢的包里最多只能装 $w$g 的糖果。在满足该条件的前提下,小石欢带走的糖果的甜度之和最大是多少?

输入格式

第一行给出糖果的数量 $N$ 和重量限制 $w$。($1 \le N \le 250\,000, 0 \le w \le 5N$)

接下来的 $N$ 行,每行给出每个糖果的种类 $t_i$ 和甜度 $s_i$。($t_i = \{3, 5\}, 1 \le s_i \le 10^9$)

输出格式

输出在满足条件的前提下,小石欢可以带走的糖果的最大甜度之和。

样例

输入样例 1

10 11
3 10
3 20
3 30
3 40
3 50
5 20
5 40
5 60
5 80
5 100

输出样例 1

190

说明

针对 Java/Kotlin 用户的警告! 与通常的常识不同,Java 的 Arrays.sort 内置函数以及 Kotlin 的 IntArray.sort() 是以 $O(N^2)$ 时间复杂度的算法实现的。本题的测试数据经过专门设计,使用上述函数会导致运行超时,因此在解决此问题时,请使用 Collections.sort 等其他排序函数。

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.