codeforces Gym 100187F F - Doomsday 区间覆盖贪心

时间:2022-09-30 12:40:36

F. Doomsday

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

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 will be possible to survive. But each 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 are now on the straight line, so there is no confusion and calculations should be simple.

You are given the positions of the people and the vaults on the line. You are to find the maximal number of people who can hide in vaults and think they will 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 of people, the number of vaults, the capacity of one vault and the time left to the Doomsday.

The second line contains n integers separated by spaces — the coordinates of the people on the line.

The third line contains m integers separated by spaces — the coordinates of the vaults on the line.

All the coordinates are between  - 109 and 109, inclusively.

Output

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

Sample Input

2 2 1 5
45 55
40 60

Sample Output

2

HINT

题意

有n个人,m个藏身处,每个藏身处可以藏k个人,一个人可以往左边走t米,往右边走t米,问你最后能躲几个人?

题解:

这是一个区间覆盖问题,类似贪心搞一搞就行了

代码

#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>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200101
#define mod 1000000009
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** struct node
{
int x,y;
};
bool cmp(node a,node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
ll flag[maxn];
node a[maxn];
ll b[maxn];
ll c[maxn];
int main()
{
ll n=read(),m=read(),k=read(),t=read();
for(int i=;i<n;i++)
{
int x=read();
a[i].x=x-t;
a[i].y=x+t;
}
for(int j=;j<m;j++)
b[j]=read();
sort(a,a+n,cmp);
sort(b,b+m);
int ans=;
int j=;
for(int i=;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 区间覆盖贪心的更多相关文章

  1. Educational Codeforces Round 61 F 思维 &plus; 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

  2. UVa 10382 Watering Grass (区间覆盖贪心问题&plus;数学)

    题意:有一块长为l,宽为w的草地,在其中心线有n个喷水装置,每个装置可喷出以p为中心以r为半径的圆, 选择尽量少的装置,把草地全部润湿. 析:我个去啊,做的真恶心,看起来很简单,实际上有n多个坑啊,首 ...

  3. Codeforces Gym 100231B Intervals 线段树&plus;二分&plus;贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  4. Codeforces Gym 100513F F&period; Ilya Muromets 线段树

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  5. Codeforces Gym 100513F F&period; Ilya Muromets 水题

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  6. Codeforces gym 100685 F&period; Flood bfs

    F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...

  7. GYM 101173 F&period;Free Figurines(贪心&vert;&vert;并查集)

    原题链接 题意:俄罗斯套娃,给出一个初始状态和终止状态,问至少需要多少步操作才能实现状态转化 贪心做法如果完全拆掉再重装,答案是p[i]和q[i]中不为0的值的个数.现在要求寻找最小步数,显然要减去一 ...

  8. POJ2376Cleaning Shifts&lpar;区间覆盖贪心&rpar;

    应该还是蛮简单的一题,但是因为模拟太差,一直没调出来....... \(显而易见的应该按照左区间从小到大排序,相等按照右区间大到小排序\). \(那么第一个区间的l一定要是1,而且必拿(否则没有区间能 ...

  9. Codeforces Gym H&period; Hell on the Markets 贪心

    Problem H. Hell on the MarketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vj ...

随机推荐

  1. Linux&lowbar;Shell&lowbar;脚本参数接收键盘输入

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #!/bin/bash     #提示"请输入姓名"并等待30秒,把用户的输入保存入变量name ...

  2. Oracle 建表,递增序列,触发器,分析函数row&lowbar;number&lpar;&rpar; &comma;partition by 子句。

    create table SC ( Id INTEGER, Name nvarchar2(20) , KC_Name nvarchar2(20), KC_score INTEGER , constra ...

  3. 5&period;7 NDK开发

    JNI开发流程主要分为以下6步: 编写Java源代码 将Java源代码编译成class字节码文件 用javah -jni命令生成.h头文件(-jni参数表示将class中用native声明的函数生成j ...

  4. Materialized Views 物化视图 -基础篇

    Materialized Views 物化视图 -基础篇 http://blog.csdn.net/elimago/article/details/5404019

  5. 64位系统ADB

    应该把ADB文件放在C:\Windows\SysWOW64目录下面,而不是System32下.

  6. Python新手学习基础之函数-关键字参数

    关键字参数 函数也可以使用 键 =值 的关键字参数形式被调用,这种调用形式的参数被称为关键字参数. 特别是在一个有许多参数的函数下,你想要指定参数中的部分参数,你可以使用关键字参数的方式来调用函数. ...

  7. Error contacting service&period; It is probably not running&period;

    平台:centos-6.3-i386 jdk-7u51 storm 0.9.1 python 2.6.6   hadoop 1.2.1 运行zookeeperd后显示启动成功: JMX enabled ...

  8. C&num;控制台或应用程序中两个多个Main&lpar;&rpar;方法的设置

    大多数初级程序员或学生都认为在C#控制台或应用程序中只能有一个Main()方法.但是事实上是可以有多个Main()方法的. 在C#控制台或应用程序中,在多个类中,且每个类里最多只能存在一个Main() ...

  9. redis-sentinel高可用配置(2)

    一:说明 前面我们已经配置了redis的主从配置(链接),这种主从架构有一个问题,当主master出现了故障了,怎么切换到从服务器上呢? 第一种:手动切换, 这种肯定会造成比较长一段时间的用户不能访问 ...

  10. 转&colon;D3DXVec3TransformNormal&lpar;&rpar; 与 3DXVec3TransformCoord&lpar;&rpar; 的区别

    DirectX中有两个很相似的函数,输入与输出的参数格式完全一样,都是输入一个三维向量(D3DXVECTOR3)和一个矩阵(D3DXMATRIX),输出变换之后的向量(D3DXVECTOR3). 函数 ...