#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct station
{
double price;
int st;
int ed;
bool flag;
}sta[510];
int pre[31000];
int post[31000];
int Cmax,D,Davg,N;
bool cmp(station a,station b)
{
return a.price<b.price;
}
int main()
{
scanf("%d%d%d%d",&Cmax,&D,&Davg,&N);
memset(pre,-1,sizeof(pre));
memset(post,-1,sizeof(post));
int Dmax=Davg*Cmax;
for(int i=0;i<N;i++)
{
scanf("%lf%d",&sta[i].price,&sta[i].st);
sta[i].ed=min(D,sta[i].st+Dmax);
sta[i].flag=false;
}
int totalD=0;
bool start=false;
double totalpay=0;
sort(sta,sta+N,cmp);
for(int i=0;i<N;i++)
{
while(post[sta[i].st]!=-1&&post[sta[i].st]!=sta[i].st)
{
sta[i].st=post[sta[i].st];
}
while(pre[sta[i].ed]!=-1&&pre[sta[i].ed]!=sta[i].ed)
{
sta[i].ed=pre[sta[i].ed];
}
if(sta[i].ed>=sta[i].st)
{
totalpay+=(sta[i].ed-sta[i].st)*1.0/Davg*sta[i].price;
totalD+=sta[i].ed-sta[i].st;
for(int j=sta[i].st;j<=sta[i].ed;j++)
{
pre[j]=sta[i].st;
post[j]=sta[i].ed;
}
if(sta[i].st==0)
{
start=true;
}
if(totalD>=D)
{
break;
}
}
else
{
continue;
}
}
if(start==false)
{
printf("The maximum travel distance = 0.00");
}
else
{
if(totalD<D)
{
printf("The maximum travel distance = %.2f",totalD*1.0);
}
else
{
printf("%.2f",totalpay);
}
}
return 0;
}
PAT甲1033 To Fill or Not to Fill (25)(25 分)
最新推荐文章于 2025-02-06 13:05:50 发布