博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CodeForces 1260D --- A Game with Traps】二分
阅读量:2038 次
发布时间:2019-04-28

本文共 3665 字,大约阅读时间需要 12 分钟。

【CodeForces 1260D --- A Game with Traps】二分

Description

You are playing a computer game, where you lead a party of m soldiers. Each soldier is characterised by his agility ai.

The level you are trying to get through can be represented as a straight line segment from point 0 (where you and your squad is initially located) to point n+1 (where the boss is located).

The level is filled with k traps. Each trap is represented by three numbers li, ri and di. li is the location of the trap, and di is the danger level of the trap: whenever a soldier with agility lower than di steps on a trap (that is, moves to the point li), he gets instantly killed. Fortunately, you can disarm traps: if you move to the point ri, you disarm this trap, and it no longer poses any danger to your soldiers. Traps don’t affect you, only your soldiers.

You have t seconds to complete the level — that is, to bring some soldiers from your squad to the boss. Before the level starts, you choose which soldiers will be coming with you, and which soldiers won’t be. After that, you have to bring all of the chosen soldiers to the boss. To do so, you may perform the following actions:

  • if your location is x, you may move to x+1 or x−1. This action consumes one second;
  • if your location is x and the location of your squad is x, you may move to x+1 or to x−1 with your squad in one second. You may not perform this action if it puts some soldier in danger (i. e. the point your squad is moving into contains a non-disarmed trap with di greater than agility of some soldier from the squad). This action consumes one second;
  • if your location is x and there is a trap i with ri=x, you may disarm this trap. This action is done instantly (it consumes no time).

Note that after each action both your coordinate and the coordinate of your squad should be integers.

You have to choose the maximum number of soldiers such that they all can be brought from the point 0 to the point n+1 (where the boss waits) in no more than t seconds.

Input

The first line contains four integers m, n, k and t (1≤m,n,k,t≤2⋅105, n<t) — the number of soldiers, the number of integer points between the squad and the boss, the number of traps and the maximum number of seconds you may spend to bring the squad to the boss, respectively.

The second line contains m integers a1, a2, …, am (1≤ai≤2⋅105), where ai is the agility of the i-th soldier.

Then k lines follow, containing the descriptions of traps. Each line contains three numbers li, ri and di (1≤li≤ri≤n, 1≤di≤2⋅105) — the location of the trap, the location where the trap can be disarmed, and its danger level, respectively.

Output

Print one integer — the maximum number of soldiers you may choose so that you may bring them all to the boss in no more than t seconds.

Sample Input

5 6 4 14

1 2 3 4 5
1 5 2
1 2 5
2 3 5
3 5 3

Sample Output

3

AC代码:

#include 
using namespace std;#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)#define endl '\n'const int MAXN = 2e5+5;int m,n,k,t;int a[MAXN],l[MAXN],r[MAXN],d[MAXN];bool compare(int x){
int y=a[m-x]; vector
> vec; for(int i=0;i
y) vec.push_back(make_pair(l[i],r[i])); sort(vec.begin(),vec.end()); int res=n+1,end=0; for(auto lr : vec) {
res+=2*max(0,lr.second-max(lr.first,end)); end=max(end,lr.second); } return (res<=t);}int main(){
SIS; cin >> m >> n >> k >> t; for(int i=0;i
> a[i]; sort(a,a+m); for(int i=0;i
> l[i] >> r[i] >> d[i],l[i]--; int st=0,ed=m+1; while(ed-st>1) { int mid=(st+ed)>>1; if(compare(mid)) st=mid; else ed=mid; } cout << st << endl; return 0;}

转载地址:http://biyof.baihongyu.com/

你可能感兴趣的文章
JAVA随机数之多种方法从给定范围内随机N个不重复数
查看>>
java使double保留两位小数的多方法 java保留两位小数
查看>>
Spring事务中涉及到多线程的处理方式
查看>>
实现页面登录后仍然跳回当前页面
查看>>
Jmeter 测试java并发
查看>>
简单java程序测试并发数
查看>>
Java出现No enclosing instance of type E is accessible
查看>>
java CountDownLatch测试并发数
查看>>
缓存穿透、缓存并发、缓存失效之思路变迁
查看>>
利用redis + lua解决抢红包高并发的问题
查看>>
一次查询耗时的分析过程
查看>>
Jmeter中的几个重要测试指标释义
查看>>
Tomcat 7优化前及优化后的性能对比
查看>>
VisualVM 提示 tomcat 不受此jvm支持解决办法
查看>>
如何在excel每一行数据后面都加一个逗号
查看>>
java之架构基础-动态代理&cglib
查看>>
Java Guava中的函数式编程讲解
查看>>
Eclipse Memory Analyzer 使用技巧
查看>>
Java程序内存分析:使用mat工具分析内存占用
查看>>
使用 VisualVM 进行性能分析及调优
查看>>