Codeforces Global Round 3 B. Born This Way

题意:给两段航班的起始时间a ,b   这两段航班的飞行时间分别为ta,tb  给k次删除航班的次数, 问如何让飞从A飞到B 再从B起飞到目的地的时间最久

题目链接:https://codeforc.es/contest/1148/problem/B

刚开始想的是贪心选怎么删除航班,但是贪心的话是受k影响的 所以贪心是不对的

思路: 枚举a中要删除多少个航班,在对应到b中还有多少次剩余的删除次数用来继续删除一段连续的航班

因为是单增 可以用二分查找

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 #define pb push_back
 5 const int maxn =2e5+10;
 6 int a[maxn];
 7 int b[maxn];
 8 
 9 int main()
10 {
11     ios::sync_with_stdio(false);
12     cin.tie(0);
13     int n,m,ta,tb,k;
14     cin>>n>>m>>ta>>tb>>k;
15     for(int i=1;i<=n;i++)
16     {
17         cin>>a[i];
18         a[i]+=ta;
19     }
20     for(int i=1;i<=m;i++)
21     {
22         cin>>b[i];
23     }
24     int ans=0;
25     for(int i=0;i<=k;i++) //a删去多少个
26     {
27         if(i>=n)
28         {
29             cout<<-1<<'\n';
30             return 0;
31         }
32         int x=lower_bound(b+1,b+1+m,a[i+1])-b;
33         if(x+k-i>m)
34         {
35             cout<<-1<<'\n';
36             return 0;
37         }
38         ans=max(ans,b[x+k-i]+tb);
39     }
40     cout<<ans<<'\n';
41 
42 
43 
44 }
View Code

猜你喜欢

转载自www.cnblogs.com/winfor/p/12941825.html
今日推荐