C. Road to Cinema

题意:n辆车分别有对应的价格和油箱容量,有2种行驶模式,分别是

① 1km 1min 2L

② 1km 2min 1L

问从坐标原点x=0到x=s,在t分钟内至少花费多少钱。若不能到达,则输出-1

思路:二分出t分钟内能到达的最小油箱容量

#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int MOD=1e9+7;
//ll a[N][N],sum[N],dis[N];
ll g[N];
ll n,k,s,t;
struct node{
    ll c,v;
}car[N];

bool check(ll v){
    ///ask (x+2y)min
    ll need=0;
    for(int i=1;i<=k+1;i++){
        ll dis=g[i]-g[i-1] ;
        if(dis>v) return false;
        else if(dis*2<=v)    need+=dis;
        else    need+=3*dis-v;
    }
//    cout <<"need="<<need<<endl;
//puts("**********");
    return need<=t;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    cin >>n>>k>>s>>t;
    for(int i=1;i<=n;i++)   cin >> car[i].c>>car[i].v;
    for(int i=1;i<=k;i++)   cin >> g[i];
    g[k+1]=s;
    sort(g+1,g+1+k);
    ll l=1,r=1e18+8,ans=-1;
    while(l<=r){
        ll mid=l+r >> 1;
        if(check(mid))  ans=mid,r=mid-1;
        else    l=mid+1;
    }
    if(ans==-1){
        cout << ans << endl;
        return 0;
    }
    set<ll> st;
//    cout <<"ans="<<ans<<endl;
    for(int i=1;i<=n;i++){
        if(car[i].v>=ans)   st.insert(car[i].c);
    }
    if(st.size()==0)    cout << -1 << endl;
    else    cout << *st.begin()<<endl;

    return 0;
}