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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 of employees must receive integer salaries, with employee i paid within . Total pay may not exceed budget , and minimum salaries are affordable. Maximize the middle element of the sorted salaries.
Input
First line: . Each of the next lines contains .
Output
Print the maximum possible median salary.
Subtasks
- Subtask 1 (20 points): ; odd; ; ; .
- Subtask 2 (30 points): ; odd; ; ; .
- Subtask 3 (50 points): ; odd; ; ; .
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.