跳到正文

个人记录

d

deepshits约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年8月9日
收录
2026年8月9日
更新
2026年11月18日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
const long long INF=1e18;
#define int long long
int n,ans=-1,d,k,q[600001],dp[600001],jl[600001],fs[600001],x[500001],s[500001];
int Max(int x,int y){
	if(x<=y){
		return y;
	}
	return x;
	
}
bool check(int m){
	int p=0,tp=1,tl=0;
    dp[0]=0;
	for(int i=1;i<=n;i++)dp[i]=-INF;
	for(int i=1;i<=n;i++){
		while(jl[i]-jl[p]>=Max(1,d-m)&&p<i){
			while(tp<=tl&&dp[q[tl]]<=dp[p])tl--;
			q[++tl]=p++;
		}
		while(tp<=tl&&jl[i]-jl[q[tp]]>d+m)tp++;
		if(tp>tl||dp[q[tp]]==-INF)continue;
		else dp[i]=dp[q[tp]]+fs[i];
		if(dp[i]>=k)return true;
	}
	return false;
}
signed main(){
    cin>>n>>d>>k;
    for(int i=1;i<=n;i++){
    	cin>>jl[i]>>fs[i];
	}
	int l=0,r=1e9;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans;
	return 0;
}
原文