From f57576a2205d379ef439d975614ce00ec492be3c Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sun, 13 Oct 2024 14:00:50 +0800 Subject: [PATCH] update --- src/P3957/P3957.cpp | 61 ++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/src/P3957/P3957.cpp b/src/P3957/P3957.cpp index af92663..128cc9e 100644 --- a/src/P3957/P3957.cpp +++ b/src/P3957/P3957.cpp @@ -9,7 +9,8 @@ using ll = long long; auto &is = std::cin; auto &os = std::cout; -const ll max_n = 5e5+5, ll_min{std::numeric_limits::min()}; +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; @@ -21,33 +22,47 @@ void flush_exit(){ _Exit(0); } +bool check(const ll coin){ + for(ll i{0};i=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; } - - for(ll coin{0};coin<=(points[n].posit-d);++coin){ - for(ll i{0};i=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){ - os< g = x[n]-d + 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; } } - os<<-1<<'\n'; + + os<<(ans==ll_max?-1:ans)<<'\n'; }