#define NDEBUG #include #include #include #include #include #define NV(v)#v<<" : "<<(v) #ifdef NDEBUG #define DEBUG(code) #else #define DEBUG(code){code} #endif using ll = long long; #ifdef NDEBUG auto &is = std::cin; #else auto is = std::ifstream("/root/dev/cpp/algorithm_2024/src/P3957/P3957_9.in"); #endif auto &os = std::cout; const ll max_n = 5e5+5, ll_min{std::numeric_limits::min()}, ll_max{std::numeric_limits::max()}; ll n, d, k; struct Point{ ll posit,score; }points[max_n]; ll dp[max_n]; void flush_exit(){ os<=0;from--){ ll dis{points[i].posit-points[from].posit}; if(min_step<=dis){ if(dis<=max_step){ if(dp[from]==ll_min)continue; dp[i] = std::max(dp[i],dp[from]+points[i].score); if(dp[i]>=k){ return true; } }else{ break; } } } } return false; } int main(){ is>>n>>d>>k; for(ll i{1};i<=n;++i){ is>>points[i].posit>>points[i].score; } // const ll max_coin{(ll)1e9+5};//d+g = x[n] -> g = x[n]-d我的推导是这样的,但是错了,必须将max_coin设置为1e5+5也就是s[i]最大值,会TLE最终研究了一下应该是作者卡时间 const ll max_coin{std::min(std::max(d-1,points[n].posit-d),(ll)1e4)};//d+g = x[n] -> g = x[n]-d我的推导是这样的,但是错了,必须将max_coin设置为1e5+5也就是s[i]最大值,会TLE最终研究了一下应该是作者卡时间 ll l{0},r{max_coin},ans{ll_max}; while(l<=r){ ll mid{(l+r)/2}; const bool check_ret{check(mid)}; if(check_ret){ ans = mid; r=mid-1; }else{ l=mid+1; } DEBUG( os<