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

从零到一:手把手教你用STM32F103C8T6打造个人专属开发板(附立创EDA工程与源码) 本文详细介绍了如何使用STM32F103C8T6微控制器从零开始设计和制作个人专属开发板。内容涵盖硬件选型、原理图设计、PCB布局、功能验证等全流程,并提供了立创EDA工程文件和源码,帮助开发者深入理解STM32开发板的硬件架构与设计要点。 阅读详情
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 );
}



【QNX+Android虚拟化方案】00 - 系列文章链接汇总 阅读详情

相关推荐

ASM磁盘通过rebalance迁移

一、实施要点: 1、数据迁移前,如果库不大,最好全库备份一次 2、进行数据平衡时,数据磁盘是添加到现有磁盘组,而不是重新建一个磁盘组 3、本次实施过程,服务器只有1张HBA卡,本次实施先取消原有的多路径,只保留旧有存储单路径,另一个FC口插上新存储的路径。待迁移完成后,再配置新存储的多路径 二、实施步骤 1.查询并配置ASM磁盘 [root@rac1 ~]# /sbin/scsi_id...

qq_40673916的博客 1370

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

【ROS】usb_cam相机标定

1. 唠叨两句 当我们要用相机做测量用途时,就需要做相机标定了,不然得到的计算结果会有很大误差,标定的内容包括三部分:内参,外参还有畸变参数。所以标定的过程就是要求得上面这些参数。 以前弄这个事估计挺麻烦,需要做实验和计算才能得到,现在通过ros的开源包几分钟就能完成相机标定,感激! 具体的内外参和畸变系数的说明,可以看看Reference里面的第一个链接,写得很详细。 2. 准备工作 要准备三样东西: usb_cam的ROS启动包 相机标定的ROS包 还有一个用于标定的棋盘格 1)usb_cam启动包

Will_Ye的博客 8199

B. Kefa and Company

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

weixin_30570101的博客 233

OctoMag: An Electromagnetic System for 5-DOF Wireless Micromanipulation

电磁线圈组驱动经典系统,可以作为参考。 OctoMag: 用于5自由度无线微操作的一个电磁铁系统 OctoMag: An Electromagnetic System for 5-DOF Wireless Micromanipulation [1] Paper Link Authors: J. J. Abbott, etc. 2010, TRO IEEE Transactions on Robot...

XU Yangxin的博客 1665

YOLOv5改进策略|实战应用案例|YOLOv5苹果成熟度检测 ,准确率提升4.6%

苹果作为世界四⼤⽔果之⼀,富含多种维⽣素和矿物质,⼀直深受世界各地消费者的喜爱。据联 合国粮⻝及农业组织统计,全球⽔果产量中,苹果位列第⼆位,仅次于葡萄(贾等⼈,2020 )。然⽽,⼤多数苹果果实都是⼿⼯采摘的,这样的⽣产⽅法效率很低。此外,随着⼈⼝⽼龄化 和农村劳动⼒⼤量涌⼊城市,⽔果种植⾏业的劳动⼒成本也相应上升。所有这些因素都显着影响 着⽔果产品的市场竞争⼒。因此,实时⾼效采收苹果等⽔果,降低采收成本势在必⾏。基于机器 视觉的⽔果采摘机器⼈可以利⽤其信息感知来识别和采摘⽔果。

斌擎科技 2207

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

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

luciozhang的博客 1630

【读代码】SQLBot:开源自然语言转SQL智能助手原理与实践

SQLBot是 DataEase 团队开源的自然语言转 SQL 智能助手,致力于让非技术用户也能通过自然语言与数据库对话,自动生成 SQL 查询,实现自助数据分析、智能BI问答、报表生成等场景。SQLBot 结合了大语言模型(LLM)、数据库元数据解析、SQL解析与执行等多项技术,具备强大的多数据库适配能力和灵活的扩展性。降低数据分析门槛,让业务人员无需掌握SQL即可获取数据洞察支持多种数据库类型,适应企业多样化数据环境提供可扩展的API和插件机制,便于集成到各类BI、数据平台和业务系统。

kakaZhui的博客 829

Codeforces 580B: Kefa and Company(前缀和)

http://codeforces.com/problemset/problem/580/B 题意:Kefa有n个朋友,要和这n个朋友中的一些出去,这些朋友有一些钱,并且和Kefa有一定的友谊值,要求这些朋友间的贫富差距(拥有的钱的数量)小于d,要求Kefa邀请出来的朋友的友谊值和最大,并输出这个最大值。 #include &lt;stdio.h&gt; #include &lt;str...

执念 790

YOLO26魔改:ICIP2026 SDTA|单深度转置注意力注入C2PSA,长程依赖与局部细节双增强,mAP提升显著

多尺度适配:SDTA的深度卷积与C2PSA的空间注意力结合,增强对多尺度目标的结构感知,改善遮挡与密集场景下的检测鲁棒性。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 291

基于 Simulink 的固态变压器(SST)多级协同控制实战教程

《固态变压器多级协同控制仿真指南》摘要: 本教程详细讲解了基于Simulink的固态变压器(SST)三级架构建模与控制方法。核心内容包含:1)搭建级联H桥整流(CHB)、双有源桥(DAB)和逆变器(VSI)的三级主电路;2)提出创新的多级协同控制策略,通过功率前馈实现输入输出级动态匹配;3)给出系统级功率平衡、单元级均压控制的具体实现方案。教程特别强调解决实际工程中的关键问题:代数环处理、软启动设计和刚性系统求解器选择,并提供了硬件在环(HIL)仿真建议。附带的MATLAB代码示例可直接用于实现电容电压均衡

xiaoheshang_123的博客 116

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的博客 495

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

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

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

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的博客 110

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

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

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的博客 214

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 1091

接上一篇 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

代码改变世界 1499

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

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

weixin_30808253的博客 271

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的博客 599

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

九野的博客 1958
上一篇: 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、付费专栏及课程。

余额充值