Codeforces Round #321 (Div. 2) B. Kefa and Company 二分
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 mi, si(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个人,告诉你每个人拥有多少钱,并且好感度是多少
如果在公司里面存在有一个人的钱大于等于他的话,这个人就会不开心
然后问你怎么安排,使得好感度最高
题解:
先排序,然后暴力
维护一个区间,这个区间都是可以选择的,至于怎么维护这个区间,可以尺取法,也可以而且搞
看自己咯
@)1%KBO0HM418$J94$1R.jpg)
代码:
//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- ;
int Num;
//const int inf=0first7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';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=;i<=n;i++)
A[i].first = read(),A[i].second=read();
sort(A+,A++n);
for(int i=;i<=n;i++)
sum[i]=sum[i-]+A[i].second;
ll ans = ;
ll ddd =;
for(int i=;i<=n;i++)
{
int r = upper_bound(A+,A++n,node{A[i].first+d-1LL,ddd}) - A;
ans = max(ans,sum[r-]-sum[i-]);
}
printf("%I64d\n",ans);
}
Codeforces Round #321 (Div. 2) B. Kefa and Company 二分的更多相关文章
- Codeforces Round #321 (Div. 2)-B. Kefa and Company,区间最大值!
->链接在此<- B. Kefa and Company time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)
排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...
- Codeforces Round #321 (Div. 2) E. Kefa and Watch 线段树hash
E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/prob ...
- 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 ...
- Codeforces Round #321 (Div. 2) A. Kefa and First Steps 水题
A. Kefa and First Steps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/58 ...
- Codeforces Round #321 (Div. 2) D. Kefa and Dishes 状压dp
题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 W ...
- codeforces水题100道 第十四题 Codeforces Round #321 (Div. 2) A. Kefa and First Steps (brute force)
题目链接:http://www.codeforces.com/problemset/problem/580/A题意:求最长连续非降子序列的长度.C++代码: #include <iostream ...
- Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)
http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...
- Codeforces Round #321 (Div. 2) A. Kefa and First Steps【暴力/dp/最长不递减子序列】
A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- Missing artifact com.sun:tools:jar:1.5.0的解决方案
今天在用maven的时候遇到一个问题pom.xml提示Missing artifact com.sun:tools:jar:1.5.0 试过改eclipse的eclipse.ini文件,也试过在ecl ...
- bzoj4525: [Usaco2016 Jan]Angry Cows
二分. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; + ...
- Java内省
什么是内省? Java语言对bean类属性.事件的一种缺省处理方法,例如类A中有属性name,那我们可以通过getName,setName来得到其值或者设置新的值. 什么是JavaBean? Java ...
- Birt时间参数添加My97日历控件
首先,思路: 引用My97.js然后为时间参数的textbox添加onclick事件 1.将My97添加到项目中的webcontent目录下(如图:) 2.添加My97引用 在项目路径下找到该文件\w ...
- 理解java reference
Java世界泰山北斗级大作<Thinking In Java>切入Java就提出“Everything is Object”.在Java这个充满Object的世界中,reference是一 ...
- RPi 2B 中文语言包
/************************************************************************* * RPi 2B 中文语言包 * 声明: * 本文 ...
- oracle导入到Excel
一.从oracle到处数据到excel文件方法一.直接从PL/SQL中,全选数据,然后复制粘贴到excel中: 方法二.同样是通过PL/SQL,在数据列中,点击右键-->导出结果-->选择 ...
- HDU 3335 Divisibility dancing links 重复覆盖
分析: dlx重复覆盖的巧用,重复覆盖的原理恰好符合本题的筛选方式,即选择一个数后,该数的倍数或约数可以保证在之后的搜索中不会被选择 于是修改一下启发函数,求解最大的重复覆盖即可. 其实不一定不被 ...
- 数据库设置表的check约束出现乱码
采用默认的方式见了一个数据库,但是有个表里需要建一个check约束.将约束保存之后再打开看到中文成了??.后来查了一下是数据库排序规则除了问题. 详见两图即可明白: 这里的约束中文显示乱码: 按下图设 ...
- “Clean Code” 读书笔记序
最近开始研读 Robert C.Martin 的 “Clean Code”,为了巩固学习,会把每一章的笔记整理到博客中.而这篇博文作为一个索引和总结,会陆续加入各章的笔记链接,以及全部读完后的心得体会 ...