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

《驾驭你的AI同事:WorkBuddy深度精通》027:11.1 私有知识库接入 本文详解WorkBuddy中私有知识库接入的RAG实现路径,聚焦“解析→切分→向量化→入库”四步流水线。强调知识源质量决定RAG上限:优先使用Markdown等结构化文档,扫描件需先OCR;切分采用递归字符+重叠(overlap)防语义断裂;向量化统一模型并附带元数据以支持溯源与权限控制;最终选择Pinecone、Weaviate或内置方案存入向量库。核心目标是让AI“基于资料说话”,杜绝“凭空编造”。 阅读详情
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 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 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.


题目大意:n个朋友,分别有金钱值和友情值,邀请其中一些来聚会,要求来聚会的每个人金钱值低于d,并且友情值总量最大,求最大的友情值。


解题思路:贪心。先排序,金钱值递增,金钱值等价时友情值递减。枚举第一个朋友,再二分查找与他金钱值差异最大的且满足条件的朋友。注意:每次找到一组朋友后,累加友情值会超时,可以先预处理一下。


代码如下:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
const int maxn=100005;
ll sum[maxn];
struct frd
{
	ll x,y;
}fd[maxn];
ll cmp(frd u,frd v)
{
	if(u.x!=v.x)
		return u.x<v.x;
	else
		return u.y>v.y;
}
int main(void)
{
	ll n,d,ans=0,x,y;
	scanf("%I64d%I64d",&n,&d);
	for(ll i=0;i<n;i++)
	{
		scanf("%I64d%I64d",&fd[i].x,&fd[i].y);
	}
	sort(fd,fd+n,cmp);
	for(ll i=0;i<n;i++)
	{
		if(!i)
			sum[i]=fd[i].y;
		else
			sum[i]=sum[i-1]+fd[i].y;
	}
	for(ll i=0;i<n;i++)
	{
		ll cur=0,md=i;
		ll hg=n-1,lw=i,mid;
		while(hg>=lw)
		{
			mid=(hg+lw)/2;
			if(fd[mid].x-fd[i].x>=d)
				hg=mid-1;
			else
			{
				lw=mid+1;
				md=mid;
			}
		}
		cur=sum[md]-sum[i]+fd[i].y;
		ans=max(ans,cur);
	}
	printf("%I64d\n",ans );
}



QLineEdit控件: 实现IP地址输入框(基于编辑信号) 在开发网络应用程序时,经常需要用户输入IP地址。直接使用普通输入框容易导致格式错误,用户体验也较差。本文将手把手教你用Qt的QLineEdit控件实现一个智能IP地址输入框。即使你是刚接触Qt的新手,也能通过本文理解核心实现原理。 阅读详情

相关推荐

PADS导出PCB正反面丝印为CAD文件的方法

本文介绍如何将PADS绘制的pcb格式的PCB文件顶底层丝印及板框导出为CAD的dxf文件格式,并且将底层丝印进行镜像为正常视角

luguodeyo的博客 3314

cf 580B

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 s

__小明003的博客 605

【C#实战】四大反编译工具深度评测与DLL逆向实战指南

本文深度评测了C#/.NET领域四大主流反编译工具:ILSpy/dnSpy、.Net Reflector、JetBrains dotPeek和Telerik JustDecompile。重点分析了它们在代码还原度、调试编辑能力及用户体验上的差异,并提供了使用dnSpy进行DLL反编译、动态调试与直接修改IL代码的完整实战指南,帮助开发者高效应对源码丢失、第三方库分析等实际场景。

weixin_29018815的博客 822

B. Kefa and Company

题目链接:http://codeforces.com/problemset/problem/580/B 题目大意:n个人,告诉你n个人的工资,但是请的客人的收入差值不能够超出给定的数字。每个人还有一个权值,现在从这n个人中选出m个人,使得他们的权值之和最大 思路:首先对每个人的工资进行排序,然后用尺取法找到一个符合条件的区间我们去计算这个区间内每个人的权值。然后找到最大的权值 ...

weixin_30570101的博客 234

无参考图像质量评估方法:BRISQUE、RankIQA、DIQA

常用的图像质量评估(IQA)分为无参考和有参考两种类型。常见的有参考图像质量评估方法有PSNR,SSIM以及VMAF。其中vmaf是针对视频来讲的,在它的评价方法里面添加了一些时域信息,如果应用于单张图片,需要做一些处理,如去除时域信息。有参考意味着图像质量是以参考图为基准。基于参考图像都是高清图像的假设,这些评价方法已经广泛应用于图像压缩以及图像传输、拼接之类的处理后图像的质量,假如这张参考图的质量本身就比较渣,那么该评价指标可信度就大大降低。

weixin_51732791的博客 3200

从仿真到现实:BeamDojo双足机器人项目实战指南(附完整配置清单)

本文提供了一份基于BeamDojo项目的双足机器人从仿真训练到现实部署的完整实战指南。详细拆解了硬件选型(如宇树G1、Jetson Orin NX、Livox Mid-360)、Isaac Gym仿真环境搭建、强化学习训练技巧(如双评论家架构、课程学习)以及关键的Sim2Real迁移策略,旨在帮助开发者将前沿研究成果转化为可落地的工程实践。

hhh00的博客 886

Codeforces#321 (Div. 2) B. Kefa and Company(前缀和,二分查找)

题意:kefa有n个朋友,Kefa 想邀请他的一些朋友去餐厅,每个朋友带两个值mi和si,分别为钱数和友情值,邀请的朋友要求最大的m和最小的m相差不大于d,求能得到的最大的友情值。 思路:按m值递增排序,枚举起点,找到符合要求的终点,计算这个区间的友情值总和,更新答案就好了,为了省时间用前缀和求区间和。注意下数据范围,答案用LL。

luciozhang的博客 1638

Halcon Camera-calibration 相关算子(一)

Halcon Camera-calibration 相关算子介绍

qq_44744164的博客 1373

cf:B Kefa and Company

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=94898#problem/B Kefa and Company Description Kefa wants to celebrate his first big salary by going to restaurant. However,

大太阳 839

单细胞转录组肿瘤细胞识别:inferCNV与CopyKAT实战解析

单细胞转录组测序(scRNA-seq)是解析肿瘤微环境的重要技术,但如何从海量细胞中准确区分恶性细胞与正常细胞,始终是数据分析的关键难题。传统marker注释在异质性肿瘤中常失效,而基于拷贝数变异(CNV)的推断方法为这一问题提供了更稳健的解决路径。CNV通过检测染色体大片段的增益或缺失,可在无先验标记的情况下识别恶性细胞,尤其适合实体瘤研究。inferCNV利用染色体滑动窗口分析相对表达量,生成直观的CNV热图;CopyKAT则结合高斯混合模型对每个细胞直接分类,输出肿瘤/正常/非整倍体标签。本文从原理出

weixin_31236101的博客 260

sap资产post记录查询时候 报错 如图

SAP资产过账查询报错AA653解决方案摘要 错误原因:系统无法计算会计年度期间的最后一天,导致资产折旧/过账失败。常见原因包括:1)未创建2025年期间版本;2)期间日期映射不完整;3)依赖日历但未生成2025年日历。 解决方法: 通过OB37维护2025年12/13个完整期间 补充缺失期间或修正结束日期 使用SCAL生成2025年工厂日历 验证步骤: 检查T009R表2025年记录完整性 测试AFAB折旧运行 重新查询资产过账 提示:建议财务团队统一维护跨年度期间数据,并在测试系统验证变更。

金牌架构师 839

Codeforces Round #321 (Div. 2) 580B. Kefa and Company

解题报告: Codeforces Round #321 Editorial B. Kefa and Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

qq1319479809的博客 496

2026年沐曦集成电路数字IC笔试试卷带答案

本文摘要: 这是一份数字IC设计笔试模拟题,包含单选题、波形分析、多选题和代码设计题。重点考察ASIC设计流程(如逻辑综合将RTL转为门级网表)、时序分析(建立时间余量计算)、跨时钟域处理(格雷码应用)、复位机制、状态机设计等核心知识点。涉及沐曦特色考点如GPU架构(SIMT模型)、国产GPU芯片(曦云C系列)及MXMACA软件栈。代码题要求实现50%占空比三分频电路,综合考察Verilog设计能力。试题强调PPA优化、低功耗技术等工程实践要点,覆盖数字IC前端设计全流程核心内容。(149字)

Open 278

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 input standard input output standard output Kefa wants to celebrate his first big s

qq_15571091的博客 396

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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 goin...

weixin_30950887的博客 111

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

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

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 firs...

weixin_30755393的博客 216

Codeforces Round #321 (Div. 2) 580B Kefa and Company(贪心 + 二分)

题目链接:点击打开链接 第一行给出n、d,接下来n行每行两个数,代表一个人的财富程度与友好值,让你从里面选人使得友好值之和最大且任意两人财富值差值小于d。 当时wa了好多发,比赛快结束时一个陌生紫名发来他的代码2333 我爆int以及思路有问题 首先按照钱数从小到大排序n个结构体,b数组存储排序后前x个人的友好总值(x >= 1 && x 数差小于d的友好值最大的人,用刚刚的b数

GKHack's Blog 1093

接上一篇 580 B. Kefa and Company [ Codeforces Round #321 (Div. 2)]

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 s

代码改变世界 1501

「日常训练」Kefa and Company(Codeforces Round #321 Div. 2 B)

题意与分析(CodeForces 580B) \(n\)个人,告诉你\(n\)个人的工资,每个人还有一个权值。现在从这n个人中选出m个人,使得他们的权值之和最大,但是对于选中的人而言,其他被选中的人的工资不能超过他的工资+d。 这题用尺取法可以漂亮的解决。尺取法按照《挑战》一书的定义,是“指对数组保存一对下标(起点和终点),然后根据实际情况交替推进两个端点直到得到答案”的一种方法,因为这种操作“很...

weixin_30808253的博客 272

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 input standard input output standard output Kefa wants to celebrate his

NYIST_TC_LYQ的博客 602

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

排序以后枚举尾部。尺取,头部单调,维护一下就好。 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typedef long long ll; //#define LOCAL const int maxn = 1e5+5; struct Node { int m,s; v...

weixin_34402090的博客 127

Codeforces round #321 (DIV. 2)

题解链接:http://www.cygmasot.com/index.php/2015/09/23/codeforces_580/ 链接 A:Kefa and First Steps 题意:the length of the maximum non-decreasing subsegment 直接搞,水题 #include #include #i

九野的博客 1962
上一篇: POJ 1062 昂贵的聘礼
下一篇: Codeforces Round #321 (Div. 2) C. Kefa and Park time limit per test
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址