瞎贪心……
记录当前为止最便宜的加油站minx
因为每一站油量最多为C,所以在当前站没加满的情况下,每走到一条新路优先加单价最小的加油站
要是加满的话,直接跳到目前的加油站
加满了油还走不到下一站就是非法情况了……(废话)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN = 200000 + 50;
double D,C,D2,P1;
double P[MAXN],pos[MAXN],ans;
int n,now = 0,minx = 1061109567;
double sy[MAXN];
int main(){
scanf("%lf%lf%lf%lf",&D,&C,&D2,&P1);
scanf("%d",&n);
for(int i = 1;i <= n;i ++){
scanf("%lf%lf",&pos[i],&P[i]);
sy[i] = C;
}
sy[0] = C;
P[0] = P1;
pos[n + 1] = D;
P[n + 1] = 1061109567;
minx = 0;
for(int i = 1;i <= n + 1;i ++){
double need = (pos[i] - pos[i - 1])/D2;
if(need > C){
printf("No Solution");
return 0;
}
if(P[minx] <= P[i - 1]){
if(need <= sy[minx]){
sy[minx] -= need;
ans += need*P[minx];
}
else{
need -= sy[minx];
ans += sy[minx]*P[minx];
minx = i - 1;
sy[minx] -= need;
ans += need*P[minx];
}
}
else{
minx = i - 1;
sy[minx] -= need;
ans += need*P[minx];
}
}
printf("%.2lf",ans);
return 0;
}