博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #321 (Div. 2) B. Kefa and Company 二分
阅读量:6230 次
发布时间:2019-06-21

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

B. Kefa and Company

Time Limit: 1 Sec  

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/580/problem/B

Description

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 Input

4 5 75 5 0 100 150 20 75 1

Sample Output

100

HINT

 

题意

给你n个人,告诉你每个人拥有多少钱,并且好感度是多少

如果在公司里面存在有一个人的钱大于等于他的话,这个人就会不开心

然后问你怎么安排,使得好感度最高

题解:

先排序,然后暴力

维护一个区间,这个区间都是可以选择的,至于怎么维护这个区间,可以尺取法,也可以而且搞

看自己咯

代码:

//qscqesze#pragma comment(linker, "/STACK:1024000000,1024000000")#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::ssecondnc_with_stdio(0);cin.tie(0)#define maxn 100006#define mod 1000000007#define eps 1e-9#define PI acos(-1)const double EP = 1E-10 ;int Num;//const int inf=0first7fffffff;const ll inf=999999999;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//*************************************************************************************ll sum[maxn];struct node{ ll first,second; friend bool operator < (const node & x,const node & y) { return x.first < y.first; }};node A[maxn];int main(){ int n=read(); ll d=read(); for(int i=1;i<=n;i++) A[i].first = read(),A[i].second=read(); sort(A+1,A+1+n); for(int i=1;i<=n;i++) sum[i]=sum[i-1]+A[i].second; ll ans = 0; ll ddd =0; for(int i=1;i<=n;i++) { int r = upper_bound(A+1,A+1+n,node{A[i].first+d-1LL,ddd}) - A; ans = max(ans,sum[r-1]-sum[i-1]); } printf("%I64d\n",ans);}

 

转载地址:http://xstna.baihongyu.com/

你可能感兴趣的文章
单链表
查看>>
linux下的僵尸进程处理SIGCHLD信号【转】
查看>>
c#中volatile关键字的作用
查看>>
Hadoop概念学习系列之搭建(windows)Eclipse/MyEclipse远程操作(Linux上)hadoop2.2.0/hadoop2.6.0 出错集(三十五)...
查看>>
淘米水的10大功效
查看>>
android 中如何分析内存泄漏
查看>>
关于简明Vim练级攻略
查看>>
遇到不可重现问题怎么办
查看>>
ASP.NET MVC5+EF6+EasyUI 后台管理系统(57)-插件---ueditor使用
查看>>
swift-数组array
查看>>
jQuery插件开发学习笔记
查看>>
现代软件工程 第十三章 【软件测试】 练习与讨论
查看>>
SharePoint Framework 开发工具和库
查看>>
团队项目建议 - 英语学习 App
查看>>
30个非常流行的提示信息插件(jQuery Tooltip Plugin)
查看>>
对PostgreSQL Merge Join 的理解
查看>>
使用Fiddler测试WCF
查看>>
iOS开发-消息转发
查看>>
JavaScript语法介绍
查看>>
Python3-for-enumerate
查看>>