CF580B.Kefa and Company

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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!

Kefa 想用自己第一笔丰厚的薪水去餐馆庆祝一番,但他需要有人作伴。

Kefa 有 nn 位朋友,每位朋友只要被 Kefa 邀请,就一定会答应前往餐馆。每位朋友由两个属性刻画:他所拥有的金钱数额,以及他与 Kefa 之间的友谊值。鹦鹉(注:此处“parrot”为题目背景设定中的角色,意指某种规则制定者)不希望公司中的任何一位朋友感到自己比其他人更贫穷(Kefa 本人不计入公司成员)。当公司中存在某人所拥有的金钱比某位朋友多出至少 dd 单位时,这位朋友就会感到贫穷。此外,Kefa 希望公司成员的总友谊值尽可能大。请帮他邀请一个最优的公司!

输入格式

The first line of the input contains two space-separated integers, n and d (1 ≤ n ≤ 105, ) — 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 ≤ 109) — the amount of money and the friendship factor, respectively.

输入的第一行包含两个用空格分隔的整数 nn 和 dd(1≤n≤1051 \leq n \leq 10^5,),分别表示基法的朋友数量以及为了感到贫穷而需满足的金钱数额最小差值。

接下来的 nn 行描述了基法的朋友们,其中第 (i+1)(i+1) 行描述第 ii 位朋友,格式为 mim_i, sis_i(0≤mi,si≤1090 \leq m_i, s_i \leq 10^9),分别表示该朋友拥有的金钱数额和友谊因子。

输出格式

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.

在第一个样例测试中,最有利可图的策略是仅由第二位朋友组成一家公司。在所有其他方案中,友谊总度数都会更差。

在第二个样例测试中,我们可以接纳所有朋友。

输入解题思路,AI测评打分。不知道怎么写?

首页