PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000191. Kefa và nhóm bạn (Kefa and Company)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Kefa và nhóm bạn (Kefa and Company)
Kefa and Company
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Kefa plans a celebration with friends. Friend has money and friendship value . Select a group in which no two friends differ in money by or more. Kefa’s own money is irrelevant. Maximize the sum of friendship values.
Input
The first line contains . Each of the next lines contains integers .
Output
Print the maximum total friendship value.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; for every .
- Subtask 3 (50 points): ; ; .
Example 1
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Explanation
Select the second friend alone; the group with money 75 has value 6.
Example 2
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
Explanation
The largest difference is 99, below 100, so all five can be selected.