题意
给定n辆车,每辆车有租费和上限油量。已知一辆车普通速度跑一公里要一单位油,费时2min,加速跑一公里要2单位油,2min。现在要在t min内从1跑到s,已知在路中有g个加油站,车通过加油站油量即补充到上限油量,加油不花费时间。问在不迟到情况下最小费用。
思路
二分。
using namespace std;
typedef struct node node;
struct node
{
int c,v;
bool operator <(const node a) const{
return v < a.v;
}
}car[201000];
int n,k,s,t;
int g[201000];
int gettime(int no){
int last = 1;
int timing = 0;
for(int i = 1;i <= k + 1;i ++){
int det = g[i] - last;
if(det > car[no].v) {
timing = 2e9 +10;
break;
}
int tmp = car[no].v - det;
timing += 2*det;
if(tmp >= det) timing -= det;
else timing -= tmp;
last = g[i];
}
//printf("%d %d %d\n",no,timing,t );
return timing;
}
int main(){
scanf("%d%d%d%d",&n,&k,&s,&t);
for(int i = 1;i <= n;i ++) scanf("%d%d",&car[i].c,&car[i].v);
for(int i = 1;i <= k;i ++) scanf("%d",&g[i]);
g[k + 1] = s;
sort(g + 1,g + 2 + k);
sort(car + 1,car + 1 + n);
int l = 1,r = n,mid = (l +r )/2;
while(l < r - 1){
mid = (l + r) /2;
if(gettime(mid) >= t) l = mid;
else r = mid;
}
int ansno;
if(gettime(l) < t) ansno = l;
else if(gettime(mid) < t) ansno = mid;
else if(gettime(r) < t) ansno = r;
else ansno = -1;
if(ansno == -1) printf("-1\n");
else{
int ans = 2e9 + 10;
for(int i = ansno;i <= n;i ++){
ans = min(ans,car[i].c);
}
printf("%d\n",ans );
}
return 0;
}