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 575 50 100150 2075 1

Sample Output

100

HINT

题意

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

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

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

题解:

先排序,然后暴力

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

看自己咯

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
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);
}

转载于:https://www.cnblogs.com/qscqesze/p/4831492.html

Codeforces Round #321 (Div. 2) B. Kefa and Company 二分相关推荐

  1. Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)

    排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...

  2. Codeforces Round #321 (Div. 2) C. Kefa and Park dfs

    C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/probl ...

  3. Codeforces Round #321 (Div. 2) D Kefa and Dishes(dp)

    用spfa,和dp是一样的.转移只和最后一个吃的dish和吃了哪些有关. 把松弛改成变长.因为是DAG,所以一定没环.操作最多有84934656,514ms跑过,实际远远没这么多. 脑补过一下费用流, ...

  4. Codeforces Round #588 (Div. 2) F. Konrad and Company Evaluation 图论 + 建反图 好题

    传送门 文章目录 题意: 思路: 题意: 给你一张nnn个点mmm条边的图,其中每个点iii初始编号为iii,边是有向的,方向为从编号大的指向编号小的.定义一个贡献为存在某三个点a,b,ca,b,ca ...

  5. Codeforces Round #321 (Div. 2)

    水 A - Kefa and First Steps /************************************************ * Author :Running_Time ...

  6. Codeforces Round #321 (Div. 2) Kefa and Company 二分

    原题链接:http://codeforces.com/contest/580/problem/B 题意: 给你一个集合,集合中的每个元素有两个属性,$m_i,s_i$,让你求个子集合,使得集合中的最大 ...

  7. Codeforces Round #321 (Div. 2) E

    终于补好了. 题目链接: http://codeforces.com/contest/580/problem/E E. Kefa and Watch time limit per test 1 sec ...

  8. Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分

    C. Vasya and Basketball 题目连接: http://codeforces.com/contest/493/problem/C Description Vasya follows ...

  9. Codeforces Round #127 (Div. 1) E. Thoroughly Bureaucratic Organization 二分 数学

    E. Thoroughly Bureaucratic Organization 题目连接: http://www.codeforces.com/contest/201/problem/E Descri ...

最新文章

  1. 常见面试题学习(1)
  2. 芯片技术从未止步 助力AI安防迈向新阶段
  3. Oracle常用字段数据类型/to_char函数
  4. 为什么文件名要小写?
  5. oracle中快速复制数据表(创建数据表)
  6. 云信小课堂|5分钟快速实现安卓端PK连麦场景
  7. RocketMq namesvr 最佳实践
  8. hooks的常用Api
  9. 兰州大学计算机调剂2020,兰州大学2020考研调剂公告
  10. Spring 2 和 JPA 简介
  11. HDU 6191 2017广西邀请赛:Query on A Tree(字典树启发式合并)
  12. 【GNN】百度「NLP」面试的一点总结
  13. Monkeyrunner介绍
  14. sql脚本 windows导出 linux乱码,mysql query browser中文乱码的解决方法
  15. 第一章、Android基础入门 - Android移动开发基础笔记
  16. Centos7 连接wifi (PEAP)
  17. opencv-python 读取视频时如何判断读取到最后一张
  18. 织梦php模板在哪个文件夹,织梦模板如何修改默认templets模板文件夹名称的方法...
  19. Overleaf在线版常用代码
  20. html代码轮播图片错位,可拖动选项卡嵌套图片轮播时图片错位的问题

热门文章

  1. 女方父母总是插手家里的事怎么办?
  2. 晚上没有路灯,我骑的很慢
  3. 不想跑滴滴,如何利用汽车赚钱?
  4. 熊猫烧香当年到底有多残忍?
  5. 自我投资,最好的方式就是写作
  6. 公司行政的未来在哪里?要不要转行?
  7. OpenCV之图像的混合
  8. ssis zip压缩文件_SSIS平面文件与原始文件
  9. 将PowerShell连接到SQL Server –使用其他帐户
  10. OpenBUGS抽样数据基本操作