Description:
\quad You are playing a a a computer game, where you lead a party of m soldiers. Each soldier is characterised by his agility a i a_{i} ai.
\quad The level you are trying to get through can be represented as a straight line segment from point 0 0 0 (where you and your squad is initially located) to point n + 1 n+1 n+1 (where the boss is located).
\quad The level is filled with k k k traps. Each trap is represented by three numbers l i , r i l_{i},r_{i} li,riand d i d_{i} di. l i l_{i} li is the location of the trap, and d i d_{i} 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 l i l_{i} li), he gets instantly killed. Fortunately, you can disarm traps: if you move to the point r i r_{i} ri, you disarm this trap, and it no longer poses any danger to your soldiers. Traps don’t affect you, only your soldiers.
\quad You have t t 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
x
x, you may move to
x
+
1
x+1
x+1 or
x
−
1
x−1
x−1. This action
consumes one second; - if your location is
x
x
x and the location of your squad is
x
x
x, you may
move to x + 1 x+1 x+1 or to x − 1 x−1 x−1 with your squad in one second. You may not
perform this action if it puts some soldier in danger ( i i i. e e e. the
point your squad is moving into contains a non-disarmed trap with d i d_{i} di
greater than agility of some soldier from the squad). This action
consumes one second; - if your location is
x
x
x and there is a trap
i
i
i with
r
i
=
x
r_{i}=x
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.
\quad You have to choose the maximum number of soldiers such that they all can be brought from the point 0 0 0 to the point n + 1 n+1 n+1 (where the boss waits) in no more than t t t seconds.
Input
\quad The first line contains four integers m , n , k m, n, k m,n,k and t t t ( 1 ≤ m , n , k , t ≤ 2 ∗ 1 0 5 , n < t ) \left(1≤m,n,k,t≤2*10^{5} ,n<t\right) (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.
\quad The second line contains m integers a 1 , a 2 . . . a m ( 1 ≤ a i ≤ 2 ∗ 1 0 5 ) a_{1},a_{2}...a_{m}\left(1≤a_{i}≤2*10^{5} \right) a1,a2...am(1≤ai≤2∗105), where ai is the agility of the i-th soldier.
\quad Then k k k lines follow, containing the descriptions of traps. Each line contains three numbers l i , r i l_{i},r_{i} li,riand d i d_{i} di. ( 1 ≤ l i ≤ r i ≤ n , 1 ≤ d i ≤ 2 ∗ 1 0 5 ) \left(1≤l_{i}≤r_{i}≤n,1≤d_{i}≤2*10^{5} \right) (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
\quad 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 t t seconds.
Example
input
5 6 4 14
1 2 3 4 5
1 5 2
1 2 5
2 3 5
3 5 3
output
3
Note
\quad In the first example you may take soldiers with agility 3, 4 and 5 with you. The course of action is as follows:
- go to 2 2 2 without your squad;
- disarm the trap 2 2 2;
- go to 3 3 3 without your squad;
- disartm the trap 3 3 3;
- go to 0 0 0 without your squad;
- go to 7 7 7 with your squad.
- The whole plan can be executed in
13
13
13 seconds.
\quad 这道题的题意我感觉是有坑的,比赛的时候一直没读清楚条件。
题意就是长度为 n n n的地形有 m m m个士兵,和 k k k个陷阱,给你 t t t时间,每个士兵都有自己的灵敏度。在 l i l_{i} li处有伤害度为 d i d_{i} di的陷阱,可以在位置 r i r_{i} ri处解除。可以向左向右走,每走一步消耗一秒,解除炸弹不需要时间,当此位置陷阱的伤害大于士兵的灵敏度不可以走过去,炸弹对你没有影响,求在 t t t时间内最多可以带过去多少士兵。
\quad 对于每一个炸弹,都分为炸弹位置,和拆弹位置。
对于当前前面有炸弹时,我们要考虑拆这个炸弹,拆完之后是继续往后拆,还是直接回去。
判断被覆盖就能知道了,然后覆盖我们用前缀和,差分处理一下即可。
直接贪心+二分就行了。
AC代码:
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n,m) printf("%d %d", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sc(n) scanf("%c",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define mem(a,n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mod(x) ((x)%MOD)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const int maxn = 3e5 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
int ret = 0, sgn = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-')
sgn = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
ret = ret*10 + ch - '0';
ch = getchar();
}
return ret*sgn;
}
inline void Out(int a) //Êä³öÍâ¹Ò
{
if(a>9)
Out(a/10);
putchar(a%10+'0');
}
int qpow(int m, int k, int mod)
{
int res = 1, t = m;
while (k)
{
if (k&1)
res = res * t % mod;
t = t * t % mod;
k >>= 1;
}
return res;
}
ll gcd(ll a,ll b)
{
return b==0?a : gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
const int N=2e5+10;
int m,n,k,t,a[N],vis[N],L,R,cnt[N];
struct node
{
int l,r,d;
} b[N];
int cmp(int a,int b)
{
return a>b;
}
bool check(int mid)
{
int low=a[mid],tot=0;
mem(cnt,0);
rep(i,1,k)
if(b[i].d>low)
{
cnt[b[i].l]++;
cnt[b[i].r+1]--;
}///差分
rep(i,1,n+1)
cnt[i]+=cnt[i-1];///走到i位置需要拆几个炸弹
rep(i,0,n+1)
tot+=(cnt[i]>=1);///拆弹总数
return tot*2+n+1<=t;
}
int main()
{
sdd(m,n);
sdd(k,t);
L=0;
R=m;
rep(i,1,m)
sd(a[i]);
rep(i,1,k)
sddd(b[i].l,b[i].r,b[i].d);
sort(a+1,a+1+m,cmp);
while(L<R)
{
int mid=L+R+1>>1;
if(check(mid))
L=mid;
else
R=mid-1;
}
pd(L);
return 0;
}