Codeforces Gym 100187F f-doomsday range covered greedy

Source: Internet
Author: User

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

Http://codeforces.com/gym/100187/problem/F

Description

Doomsday comes in t units of time. In anticipation of such a significant event n people prepared m vaults in which, as they think, it'll be possible to Sur Vive. But the vault can accommodate only k people and each person can pass only one unit of distance per one unit of time. Fortunately, all people and vaults was now on the straight line, so there was no confusion and calculations should be Simpl E.

You is given the positions of the people and the vaults on the line. You is to find the maximal number of people who can hide in vaults and think they would survive.

Input

The first line contains four integers n, m, K and T (1≤n, M, k≤200000, 1≤t≤109) separated by spaces-the number O F people, the number of vaults, the capacity of one vault and the time left to the doomsday.

The second line contains n integers separated is spaces-the coordinates of the people on the line.

The third line contains m integers separated is spaces-the coordinates of the vaults on the line.

All the coordinates is BETWEEN-109 and 109, inclusively.

Output

Output one integer-the maximal number of people who can hide in vaults and think they would survive.

Sample Input

2 2 1 5
45 55
40 60

Sample Output

2

HINT

Test instructions

There are n people, M hiding place, each hiding place can hide k person, a person can go to the left of T-meter, to the right of the T-meter, ask you finally can hide a few people?

Exercises

This is an interval coverage problem, like greedy.

Code

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)#defineMAXN 200101#defineMoD 1000000009#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************structnode{intx, y;};BOOLCMP (node A,node b) {if(a.x==b.x)returna.y<b.y; returna.x<b.x;} ll Flag[maxn];node a[maxn];ll B[maxn];ll C[MAXN];intMain () {ll n=read (), M=read (), K=read (), t=read ();  for(intI=0; i<n;i++)    {        intx=read (); a[i].x=x-T; A[i].y=x+T; }     for(intj=0; j<m;j++) B[j]=read (); Sort (A,a+n,cmp); Sort (b,b+m); intans=0; intj=0;  for(intI=0; i<n;i++)    {        if(j==m) Break;  while(b[j]<a[i].x&&j<m) J++; if(j==m) Break; if(a[i].y>=B[j]) {ans++; C[J]++; if(c[j]==k) J++; }} cout<<ans<<Endl;}

Codeforces Gym 100187F f-doomsday range covered greedy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.