#include <iostream> #include <map> using namespace std; int main() { int cmax, d, davg, n; while (cin >> cmax >> d >> davg >> n) { // 注意 while 处理多个 case // cout << a + b << endl; multimap<double, int> stationMap; while (n--) { double price; int distance; cin >> price >> distance; stationMap.insert(make_pair(price, distance)); } int farest = cmax * davg; bool way[d + 1]; for (int i = 1; i < d + 1; i++) { way[i] = false; } double price = 0; for (auto it = stationMap.begin(); it != stationMap.end(); it++) { double tempPrice = it->first; int index = it->second; int singleDistance = 0; for (int i = index + 1; i <= d && i <= index + farest; i++) { if (way[i] == false) { way[i] = true; singleDistance++; } } price += singleDistance / (davg * 1.0) * tempPrice; } int distance = 0; bool finish = true; for (int i = 1; i <= d; i++) { if (way[i]) distance++; else { finish = false; break; } } if(finish){printf("%.2f\n",price);} else printf("The maximum travel distance = %.2f\n",(double)distance); } } // 64 位输出请用 printf("%lld")