题意:从a地到b地有n个航班,b地到c地有m个航班。现在取消k个航班,使到晚到c地。

枚举取消前i个a航班,因为取消都是从小的取消起。然后看最早到b的时间,之后再取消连续的k-i个b航班。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
#define err cout<<"err"<<endl
using namespace std;
const double EPS=1e-8;
typedef long long lon;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const lon SZ=300010,SSZ=SZ*SZ,APB=4,one=1;
const lon INF=0x3f3f3f3f,mod=1000000007;
lon n,m,a[SZ],b[SZ],ta,tb,knum;

void init()
{
    cin>>n>>m>>ta>>tb>>knum;
    for(lon i=1;i<=n;++i)cin>>a[i];
    for(lon i=1;i<=m;++i)cin>>b[i];
    lon res=0;
    for(lon i=0;i<=knum;++i)
    {
        if(i>=n)
        {
            cout<<-1<<endl;
            return;
        }
        else
        {
            lon val=a[i+1]+ta;
            lon pos=lower_bound(b+1,b+1+m,val)-b;
            if(pos+(knum-i)>m)
            {
                cout<<-1<<endl;
                return;
            }
            else res=max(res,b[pos+knum-i]+tb);
        }
    }
    cout<<res<<endl;
}

void work()
{

}

void release()
{

}

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    lon casenum;
    //cin>>casenum;
    //cout<<casenum<<endl;
    //for(lon tim=1;tim<=casenum;++tim)
    //for(lon tim=1;cin>>n;++tim)
    {
        //cout<<"Case #"<<tim<<": ";
        init();
        work();
        release();
    }
    return 0;
}
01-21 00:06