博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces #321 div 2 B. Kefa and Company(尺取法)
阅读量:5115 次
发布时间:2019-06-13

本文共 2703 字,大约阅读时间需要 9 分钟。

B. Kefa and Company
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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!

Input

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 misi(0 ≤ mi, si ≤ 109) — the amount of money and the friendship factor, respectively.

Output

Print the maximum total friendship factir that can be reached.

Sample test(s)
input
4 5 75 5 0 100 150 20 75 1
output
100
input
5 100 0 7 11 32 99 10 46 8 87 54
output
111
Note

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.

 

尺取直接搞...

然后因为没开longlong wa了一发...

因为看错条件,money差值等于d也会被鄙视...所以不能取等号...

都是傻逼错误...药丸,药丸啊...

1 /************************************************************************* 2     > File Name: code/cf/#321/B.cpp 3     > Author: 111qqz 4     > Email: rkz2013@126.com  5     > Created Time: 2015年09月25日 星期五 17时21分55秒 6  ************************************************************************/ 7  8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20 #include
21 #define y1 hust111qqz22 #define yn hez111qqz23 #define j1 cute111qqz24 #define ms(a,x) memset(a,x,sizeof(a))25 #define lr dying111qqz26 using namespace std;27 #define For(i, n) for (int i=0;i
>q[i].m>>q[i].f;75 sort(q,q+n,cmp);76 // for ( int i = 0 ; i < n ; i++) cout<
<<" "<
<
View Code

 

 

转载于:https://www.cnblogs.com/111qqz/p/4839685.html

你可能感兴趣的文章
尚学堂Java面试题整理
查看>>
MySQL表的四种分区类型
查看>>
[BZOJ 3489] A simple rmq problem 【可持久化树套树】
查看>>
STM32单片机使用注意事项
查看>>
swing入门教程
查看>>
好莱坞十大导演排名及其代表作,你看过多少?
查看>>
Loj #139
查看>>
hihocoder1187 Divisors
查看>>
Azure 托管镜像和非托管镜像对比
查看>>
js window.open 参数设置
查看>>
032. asp.netWeb用户控件之一初识用户控件并为其自定义属性
查看>>
Ubuntu下安装MySQL及简单操作
查看>>
前端监控
查看>>
clipboard.js使用方法
查看>>
移动开发平台-应用之星app制作教程
查看>>
leetcode 459. 重复的子字符串(Repeated Substring Pattern)
查看>>
伪类与超链接
查看>>
centos 7 redis-4.0.11 主从
查看>>
博弈论 从懵逼到入门 详解
查看>>
永远的动漫,梦想在,就有远方
查看>>