CF580B.Kefa and Company

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.

Kefa has nn 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 dd 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, nn and dd ( 1<=n<=1051<=n<=10^{5} , ) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.

Next nn lines contain the descriptions of Kefa's friends, the (i+1)(i+1) -th line contains the description of the ii -th friend of type mim_{i} , sis_{i} ( 0<=mi,si<=1090<=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
    

说明/提示

In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.

In the second sample test we can take all the friends.

首页