# 【jzoj5350】【NOIP2017提高A组模拟9.7】【陶陶摘苹果】【动态规划】

## code

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LF double
#define LL long long
#define ULL unsigned int
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
#define fr(i,j) for(int i=begin[j];i;i=next[i])
using namespace std;
int const mn=1e6+3,mm=200+3,inf=1e9+7;
int n,m,h,K,a[mn],f[mm][mm];
struct rec{
int l,r;
};
rec b[mm];
bool cmp(rec x,rec y){
return x.r<y.r;
}
int main(){
freopen("apple.in","r",stdin);
freopen("apple.out","w",stdout);
scanf("%d%d%d%d",&n,&m,&h,&K);
fo(i,1,n)scanf("%d",&a[i]);
a[n+1]=inf;
fo(i,1,m)scanf("%d%d",&b[i].l,&b[i].r);
sort(a+1,a+n+1);
fo(i,1,m){
b[i].l=lower_bound(a+1,a+n+2,h+b[i].l)-a;
b[i].r=lower_bound(a+1,a+n+2,h+b[i].r+1)-a-1;
}
sort(b+1,b+m+1,cmp);
fo(i,1,m)fo(j,1,K){
f[i][j]=f[i-1][j];
fo(k,0,i-1)
f[i][j]=max(f[i][j],f[k][j-1]+max(b[i].r-max(b[i].l,b[k].r+1)+1,0));
}
printf("%d",f[m][K]);
return 0;
}

02-15 696

05-14 497

03-18 53

07-17 191

05-24 266

03-06 933

09-04 438

02-12 158

06-30 119

02-26 510