#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
/*
总结:这题较难,再看几遍
注意点:
1.起点可能没加油站
2.把终点站加入,更方便处理
3.退出条件:
1.达到终点站
2.中途,不能满油也无法达到下一个加油站
4.加油站的选取:
1.当前油价在可达范围内最低,加满(MAX-剩余)
2.可达范围内,有比当前低的,加油情况:
1.当前油量比need高,更新now的位置,油箱-need;
2.当前油量比need低,加need-剩余
*/
const int maxn = 510;
const int INF = 100000000;
struct station {
double price, dis;
}st[maxn];
bool cmp(station a, station b) {
return a.dis < b.dis;
}
int main() {
int n;
double Cmax, D, Davg;
cin >> Cmax >> D >> Davg >> n;
for (int i = 0; i < n; i++) {
cin >> st[i].price >> st[i].dis;
}
//最后一个放终点
st[n].price= 0;
st[n].dis = D;
sort(st, st + n, cmp);
if (st[0].dis != 0) {
printf("The maximum travel distance = 0.00");
}
else
{
int now = 0;
double ans = 0, nowTank = 0, MAX = Cmax * Davg;
while (now < n) {
int k = -1;
double priceMin = INF;
for (int i = now + 1; i <= n && st[i].dis - st[now].dis <= MAX; i++) {
if (st[i].price < priceMin) {
priceMin = st[i].price;
k = i;
if (priceMin < st[now].price) {
break;
}
}
}
// 找不到下一站
if (k == -1)break;
double need = (st[k].dis - st[now].dis) / Davg;
if (priceMin < st[now].price) {
if (nowTank < need) {
ans += (need - nowTank)*st[now].price;
nowTank = 0;
}
else {
nowTank -= need;
}
}
else {
ans += (Cmax - nowTank)*st[now].price;
nowTank = Cmax - need;
}
now = k;
}
if (now == n) {
printf("%.2f\n", ans);
}
else {
printf("The maximum travel distance = %.2f\n", st[now].dis + MAX);
}
}
return 0;
}