#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=0x3f3f3f;
struct station
{
double price,dis;
} sta[600];
int cmp(station a,station b)
{
return a.dis<b.dis;
}
int main()
{
double cmax,davg,d;
int n;
scanf("%lf%lf%lf%d",&cmax,&d,&davg,&n);
for(int i=0; i<n; i++)
{
scanf("%lf%lf",&sta[i].price,&sta[i].dis);
}
sta[n].dis=n;
sta[n].price=0;
int now=0;
double ans=0;
sort(sta,sta+n,cmp);
if(sta[now].dis!=0)
{
printf("The maximum travel distance = 0.00\n");
}
else
{
double max_length=cmax*davg;
double left_oil=0;
while(now<n)
{
int k=-1;
int min_price=0x3f3f3f;
for(int i=now+1; i<=n&&sta[i].dis-sta[now].dis<=max_length; i++)
{
if(min_price>sta[i].price)
{
k=i;
min_price=sta[i].price;
}
if(min_price<sta[now].price)
{
break;
}
}
if(k==-1)
{
break;
}
double need=(sta[k].dis-sta[now].dis)/davg;
if(min_price<sta[now].price)
{
if(left_oil*davg<sta[k].dis-sta[now].dis)
{
ans+=(need-left_oil)*sta[now].price;
left_oil=0;
}
else
{
left_oil-=need;
}
}
else
{
ans+=(cmax-left_oil)*sta[now].price;
left_oil=(cmax-need);
}
now=k;
}
if(now==n)
{
printf("%.2f\n",ans);
}
else
{
printf("The maximum travel distance = %.2f\n\n",sta[now].dis+max_length);
}
}
}
1033 To Fill or Not to Fill (25 分) (贪心)
最新推荐文章于 2023-03-28 01:34:53 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)