题解:CF580B Kefa and Company
CF580B Kefa and Company
前言。
其实本题与这道题极为相似,所以建议降橙。
思路
因为输入顺序不影响就结果,所以可以先给
AC 代码
#include<bit/stdc++.h>
using namespace std
#define N 100005
long long t,mx,n,k,x,sum[N];
struct node{
long long num,val;
}a[N];
void two_pointer(){
for(long long l=1,r=0;l<=n;l++){
while(r<n&&a[r+1].num-a[l].num<k){
r++;
}
mx=max(mx,sum[r]-sum[l-1]);
}
return;
}
bool cmp(node a,node b){
return a.num<b.num;
}
void read(){
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i].num>>a[i].val;
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i].val;
}
void init(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
}
int mian(){
init();
read();
two_pointer();
cout<<mx<<endl;
}
珍爱生命,请勿抄袭(抄抄试试?)。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构