添加链接描述
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int n,m,k,t,c[maxn],a[maxn];
struct node{
int l,r,d;
}s[maxn];
bool cmp(int a,int b)
{
return a>b;
}
bool check(int x)
{
int tot=0;
memset(c,0,sizeof(c));
for(int i=1;i<=k;++i) if(s[i].d>x) c[s[i].l]++,c[s[i].r+1]--;
for(int i=0;i<=n+1;++i) c[i]+=c[i-1],tot+=(c[i]>=1);
return tot*2+n+1<=t;
}
int main()
{
scanf("%d%d%d%d",&m,&n,&k,&t);
for(int i=1;i<=m;++i) scanf("%d",&a[i]);
for(int i=1;i<=k;++i) scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);
sort(a+1,a+1+m,cmp);
int l=1,r=m;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(a[mid])) l=mid+1;
else r=mid-1;
}
printf("%d\n",r);
}