302980: CF580B. Kefa and Company
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Kefa and Company
题意翻译
### 题目描述 Kefa 想要去餐馆庆祝一下,他有 $n$ 个朋友,每个朋友有一定的友谊值和工资。没人想觉得自己穷,所以 Kefa 邀请的朋友中两两工资差小于 $d$。现在给出朋友的信息,请求出最大友谊值是多少。 ### 输入格式 第一行是 $n$ 和 $d$,有 $n$ 个朋友,以及工资差值小于 $d$。接下来 $n$ 行给定 $n$ 个朋友的信息,第 $i$ 行表示他的工资为$m_i$,友谊值为 $s_i$。 ### 输出格式 一个整数,满足要求的前提下可以获得的最大友谊值。题目描述
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has $ n $ friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least $ d $ units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!输入输出格式
输入格式
The first line of the input contains two space-separated integers, $ n $ and $ d $ ( $ 1<=n<=10^{5} $ , ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF580B/d24d6ba93c00f6471d95f9b020d7a9d5a254f8ba.png)) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively. Next $ n $ lines contain the descriptions of Kefa's friends, the $ (i+1) $ -th line contains the description of the $ i $ -th friend of type $ m_{i} $ , $ s_{i} $ ( $ 0<=m_{i},s_{i}<=10^{9} $ ) — the amount of money and the friendship factor, respectively.
输出格式
Print the maximum total friendship factir that can be reached.
输入输出样例
输入样例 #1
4 5
75 5
0 100
150 20
75 1
输出样例 #1
100
输入样例 #2
5 100
0 7
11 32
99 10
46 8
87 54
输出样例 #2
111