This commit is contained in:
Zengtudor 2024-10-13 14:00:50 +08:00
parent 3039ac5e93
commit f57576a220

View File

@ -9,7 +9,8 @@ using ll = long long;
auto &is = std::cin; auto &is = std::cin;
auto &os = std::cout; auto &os = std::cout;
const ll max_n = 5e5+5, ll_min{std::numeric_limits<decltype(ll_min)>::min()}; const ll max_n = 5e5+5, ll_min{std::numeric_limits<decltype(ll_min)>::min()},
ll_max{std::numeric_limits<decltype(ll_max)>::max()};
ll n, d, k; ll n, d, k;
struct Point{ struct Point{
ll posit,score; ll posit,score;
@ -21,33 +22,47 @@ void flush_exit(){
_Exit(0); _Exit(0);
} }
bool check(const ll coin){
for(ll i{0};i<max_n;i++)dp[i]=ll_min;
dp[0]=0; // 注意第0个点是能到达的reachable
const ll max_step {coin+d}, min_step {std::max((ll)1,d-coin)};
for(ll i{1};i<=n;++i){
for(ll from{i-1};from>=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(){ int main(){
is>>n>>d>>k; is>>n>>d>>k;
for(ll i{1};i<=n;++i){ for(ll i{1};i<=n;++i){
is>>points[i].posit>>points[i].score; is>>points[i].posit>>points[i].score;
} }
for(ll coin{0};coin<=(points[n].posit-d);++coin){ const ll max_coin{points[n].posit-d};//d+g = x[n] -> g = x[n]-d
for(ll i{0};i<max_n;i++)dp[i]=ll_min; ll l{0},r{max_coin},ans{ll_max};
dp[0]=0; // 注意第0个点是能到达的reachable while(l<=r){
const ll max_step {coin+d}, min_step {std::max((ll)1,d-coin)}; ll mid{(l+r)/2};
for(ll i{1};i<=n;++i){ const bool check_ret{check(mid)};
for(ll from{i-1};from>=0;from--){ if(check_ret){
ll dis{points[i].posit-points[from].posit}; ans = mid;
if(min_step<=dis){ r=mid-1;
if(dis<=max_step){ }else{
if(dp[from]==ll_min)continue; l=mid+1;
dp[i] = std::max(dp[i],dp[from]+points[i].score);
if(dp[i]>=k){
os<<coin<<'\n';
flush_exit();
}
}else{
break;
}
}
}
} }
} }
os<<-1<<'\n';
os<<(ans==ll_max?-1:ans)<<'\n';
} }