#P3963. [TJOI2013] 奖学金

    ID: 2898 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心2013各省省选二叉堆枚举,暴力优先队列主席树天津

[TJOI2013] 奖学金

Description

There are cc students in Xiao Zhang's college. The ii-th student's score is aia_i, and the scholarship amount they would receive is bib_i.
You need to select nn students from these cc students to award scholarships. This mysterious person has a peculiar preference: he wants the median of the scores of the students who receive scholarships to be as large as possible, while their total scholarship amount must not exceed ff.

Input Format

The first line contains three integers, representing the number of students to select nn, the total number of students cc, and the maximum total scholarship amount ff, guaranteeing that nn is odd.

Lines 22 through (c+1)(c + 1): each line contains two integers. The (i+1)(i + 1)-th line contains the ii-th student's score aia_i and, if they are awarded a scholarship, the amount bib_i that needs to be given.

Output Format

Output one integer on a single line representing the answer. If the mysterious person's conditions cannot be met, output 1-1.

3 5 70
30 25
50 21
20 20
5 18
35 30

35
5 6 9
4 0
4 1
6 3
8 0
10 4
10 5

6

Hint

Sample 1 Explanation

Select three students with scores 55, 3535, and 5050, with a total scholarship amount of 18+30+21=6918 + 30 + 21 = 69.

Constraints

  • For 30%30\% of the testdata, it is guaranteed that n103n \leq 10^3, c2×103c \leq 2 \times 10^3.
  • For 100%100\% of the testdata, it is guaranteed that 3n1053 \leq n \leq 10^5, nc2×105n \leq c \leq 2 \times 10^5, 0f2×1090 \leq f \leq 2 \times 10^9, 0ai2×1090 \leq a_i \leq 2 \times 10^9, 0bi1050 \leq b_i \leq 10^5.

Translated by ChatGPT 5