PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000333. Tối đa hóa trung vị lương (Salary Changing)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tối đa hóa trung vị lương (Salary Changing)

Salary Changing

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An odd number nn of employees must receive integer salaries, with employee i paid within [li,ri][l_i,r_i]. Total pay may not exceed budget ss, and minimum salaries are affordable. Maximize the middle element of the sorted salaries.

Input

First line: n,sn,s. Each of the next nn lines contains li,ril_i,r_i.

Output

Print the maximum possible median salary.

Subtasks

  • Subtask 1 (20 points): 1≤n≤71\le n\le7; nn odd; 1≤li≤ri≤121\le l_i\le r_i\le12; 1≤s≤2⋅10141\le s\le2\cdot10^{14}; ∑li≤s\sum l_i\le s.
  • Subtask 2 (30 points): 1≤n<2⋅1051\le n<2\cdot10^5; nn odd; 1≤li=ri≤1091\le l_i=r_i\le10^9; 1≤s≤2⋅10141\le s\le2\cdot10^{14}; ∑li≤s\sum l_i\le s.
  • Subtask 3 (50 points): 1≤n<2⋅1051\le n<2\cdot10^5; nn odd; 1≤li≤ri≤1091\le l_i\le r_i\le10^9; 1≤s≤2⋅10141\le s\le2\cdot10^{14}; ∑li≤s\sum l_i\le s.

Examples

Input 1

3 26
10 12
1 4
10 11

Output 1

11

Explanation

Pay 11, 1, 11 (sum 23). Only one employee can receive 12, so median 12 is impossible.

Input 2

1 1337
1 1000000000

Output 2

1337

Explanation

Pay the full budget to the sole employee.