QOJ.ac

QOJ

Time Limit: 3.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#17888. 사탕 배달

Statistics

사탕을 좋아하는 아기 석환은, 집에 $N$개의 사탕이 들어있는 자루를 들여놓았다. 자루에는 두 가지 종류의 사탕이 있는데, 작은 사탕은 3g의 무게를 가지고, 큰 사탕은 5g의 무게를 가진다. 똑똑한 아기 석환은 자루에 있는 모든 사탕에 대해서, 그 사탕의 당도 $s_i$ 를 계산해 놓았다. $s_i$는 양의 정수로, $s_i$ 가 클 수록 사탕은 달콤하다.

shake! 2019 대회에 참가하기 위해 짐을 싸고 있는 아기 석환은, 달콤한 사탕을 최대한 많이 담아가서 대회 도중 당분을 보충하려고 한다. 하지만, 연약한 아기 석환은 가방에 최대 $w$g의 사탕만을 담을 수 있다. 아기 석환이 이 조건을 만족하면서 사탕을 담았을 때, 담아간 사탕의 당도의 합은 최대 얼마가 될 수 있을까?

Input

첫 번째 줄에 사탕의 개수 $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$).

Output

아기 석환이 조건을 만족하면서 담아갈 수 있는 사탕의 당도의 최대 합을 출력하라.

Examples

Input 1

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

Output 1

190

Note

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.