链接
http://codeforces.com/gym/100187/problem/G
题解
首先,不可能这样走:
因为不如这样走:
所以最后的结果就应该是这样的:
就是说每个地窖吸收的人都是一段区间
那我就从左到右贪心,对于每个地窖我在
[pos−t,pos+t]
[
p
o
s
−
t
,
p
o
s
+
t
]
区间内尽量吸收左端的人
思路总结
只要发现了上面描述的性质,再换一个角度考虑问题(考虑地窖吸收那些人),就能做出来了
代码
//̰ÐÄ
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <queue>
#define maxn 200010
using namespace std;
int read(int x=0)
{
char c, f=1;
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-48;
return f*x;
}
int N, M, K, T, cnt, a[maxn], b[maxn];
void init()
{
int i;
N=read(), M=read(), K=read(), T=read();
for(i=1;i<=N;i++)a[i]=read();
for(i=1;i<=M;i++)b[i]=read();
sort(a+1,a+N+1);
sort(b+1,b+M+1);
}
void work()
{
int i, j, res;
for(i=1,j=1;i<=M;i++)
{
while(a[j]<b[i]-T and j<=N)j++;
res=K;
while(res and a[j]<=b[i]+T and j<=N)j++, res--, cnt++;
}
printf("%d",cnt);
}
int main()
{
init();
work();
return 0;
}