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 &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;
struct Point{
ll posit,score;
@ -21,13 +22,7 @@ void flush_exit(){
_Exit(0);
}
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){
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)};
@ -39,8 +34,7 @@ int main(){
if(dp[from]==ll_min)continue;
dp[i] = std::max(dp[i],dp[from]+points[i].score);
if(dp[i]>=k){
os<<coin<<'\n';
flush_exit();
return true;
}
}else{
break;
@ -48,6 +42,27 @@ int main(){
}
}
}
}
os<<-1<<'\n';
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{points[n].posit-d};//d+g = x[n] -> 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<<(ans==ll_max?-1:ans)<<'\n';
}