A. Closing ceremony
time limit per test

2 seconds

memory limit per test

256 megabytes

The closing ceremony of Squanch Code Cup is held in the big hall with n × m seats, arranged in n rows, m seats in a row. Each seat has two coordinates (x, y) (1 ≤ x ≤ n, 1 ≤ y ≤ m).

There are two queues of people waiting to enter the hall: k people are standing at (0, 0) and n·m - k people are standing at (0, m + 1). Each person should have a ticket for a specific seat. If person p at (x, y) has ticket for seat (xp, yp) then he should walk |x - xp| + |y - yp|to get to his seat.

Each person has a stamina — the maximum distance, that the person agrees to walk. You should find out if this is possible to distribute all n·m tickets in such a way that each person has enough stamina to get to their seat.

Input

The first line of input contains two integers n and m (1 ≤ n·m ≤ 104) — the size of the hall.

The second line contains several integers. The first integer k (0 ≤ k ≤ n·m) — the number of people at (0, 0). The following k integers indicate stamina of each person there.

The third line also contains several integers. The first integer l (l = n·m - k) — the number of people at (0, m + 1). The following lintegers indicate stamina of each person there.

The stamina of the person is a positive integer less that or equal to n + m.

Output

If it is possible to distribute tickets between people in the described manner print "YES", otherwise print "NO".

Examples
input
2 2
3 3 3 2
1 3
output
YES
input
2 2
3 2 3 3
1 2
output
NO

题目大意:n*m个座位, 有n*m个人,一开始有k个人在(0,0)点上,l个人在(0,m+1)点上,每个人有对应的体力值,体力值即为可以行走的距离(曼哈顿距离),问是否存在一种方案是每个人花费的体力不超过上限,且每个人都有位置坐。


贪心:对于前k个人,我们按照体力排序,显然找到一个以距离(0,m+1)尽可能远为第一关键字,与(0,0)尽可能远为第二关键字的位置,那么这个人就应该在这个位置。之后l个人放到与(0,m+1)尽可能远的且没有人的位置,检测是否存在这种可能。


AC code

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
#include<ctime>
#include<cstring>
#define yyj(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout);
#define llg long long
#define maxn 10010
using namespace std;
llg i,j,k,n,m,k1,k2,t1,t2,bj[maxn],x,y,l,len,a[maxn],b[maxn],maxl;
bool f;
int main()
{
yyj("");
cin>>n>>m>>k1;
for (i=;i<=k1;i++) cin>>a[i];
sort(a+,a+k1+);
cin>>k2;
for (j=;j<=k2;j++) cin>>b[j];
sort(b+,b+k2+);
int c[n+][m+];
for (i=;i<=n;i++) for (j=;j<=m;j++) c[i][j]=;
for (k=;k<=k1;k++)
{
f=false; maxl=;
for (i=;i<=n;i++)
for (j=;j<=m;j++)
if (i+j<=a[k] && i+m+-j>maxl && c[i][j]==)
{
f=true;
x=i,y=j;
maxl=i+m-j+;
}
if (f)
{
c[x][y]=;
}
else
{
cout<<"NO";
return ;
}
}
for (k=;k<=k2;k++)
{
maxl=,f=false;
for (i=;i<=n;i++)
for (j=;j<=m;j++)
if (c[i][j]== && i+m+-j>maxl && i+m+-j<=b[k])
{
f=true;
x=i; y=j;
maxl=i+m+-j;
}
if (f)
{
c[x][y]=;
}
else
{
cout<<"NO";
return ;
}
}
cout<<"YES";
return ;
}

Codeforces 720A. Closing ceremony的更多相关文章

  1. codeforces 720A:Closing ceremony

    Description The closing ceremony of Squanch Code Cup is held in the big hall with n × m seats, arran ...

  2. CF720A Closing ceremony 贪心

    正解:贪心 解题报告: 传送门! 先考虑如果只有一列怎么搞?那就肯定是尽量走到最远的地方 然后用点儿类似的思想,现在考虑有两列的情况QAQ 为了方便表述,这里给每个位置两个值,a表示离一号入口的距离, ...

  3. 题解 [CF720A] Closing ceremony

    题面 解析 首先贪心地想一想, 一个人我们肯定让她坐得尽量远, 那到底坐到哪里呢? 考虑先让下面的人先坐, 那他们就要尽量把离上面入口远的位置坐掉, 因此把位置按离上面的距离从大到小排序, 再一个个看 ...

  4. 退役前的最后的做题记录upd:2019.04.04

    考试考到自闭,每天被吊打. 还有几天可能就要AFO了呢... Luogu3602:Koishi Loves Segments 从左向右,每次删除右端点最大的即可. [HEOI2014]南园满地堆轻絮 ...

  5. 2018SDIBT_国庆个人第二场

    A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...

  6. Lunch War with the Donkey CSU - 2084

    Jingze is a big figure in California State University for his stubbornness. Because of his new failu ...

  7. DP:0

    小故事: A * "1+1+1+1+1+1+1+1 =?" * A : "上面等式的值是多少" B : *计算* "8!" A *在上面等式 ...

  8. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)

    A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...

  9. Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence 栈

    C. Replace To Make Regular Bracket Sequence 题目连接: http://www.codeforces.com/contest/612/problem/C De ...

随机推荐

  1. Codeforces Round #376 (Div. 2) C D F

    在十五楼做的cf..一会一断...比赛的时候做出了ABCF 就没有时间了 之后没看题解写出了D..E是个神奇的博弈(递推或者dp?)看了题解也没有理解..先写了CDF.. C 有n个袜子 每个袜子都有 ...

  2. DS Tree 已知先序、中序 => 建树 => 求后序

    参考:二叉树--前序和中序得到后序 思路历程: 在最初敲的时候,经常会弄混preorder和midorder的元素位置.大体的思路就是在preorder中找到根节点(根节点在序列的左边),然后在mid ...

  3. java.lang.UnsupportedClassVersionError: Bad version number in .class file异常

    java.lang.UnsupportedClassVersionError: Bad version number in .class file异常 部署工程时也出现过因为版本不同引起的问题,那时我 ...

  4. eclipse工程加入jquery.min.js报错:missing semicolon

    1,注释修改项目目录下的.project文件 <?xml version="1.0" encoding="UTF-8"?> <projectD ...

  5. 蓝牙--对象交换协议(OBEX)

    1.OBEX协议概述 OBEX是IrOBEX的简称,IrOBEX协议是红外数据协会IrDA开发的用于红外数据链路上数据对象交换的会话层协议.OBEX是一种紧凑高效的二进制协议,功能类似于HTTP协议. ...

  6. Java微信公众号开发

    微信公众平台是腾讯为了让用户申请和管理微信公众账号而推出的一个web平台.微信公众账号的种类可以分为3种,并且一旦选定不可更改.按照功能的限制从小到大依次为:订阅号.服务号.企业号.个人只能注册订阅号 ...

  7. 转: 带你玩转Visual Studio——带你理解多字节编码与Unicode码

    上一篇文章带你玩转Visual Studio——带你跳出坑爹的Runtime Library坑帮我们理解了Windows中的各种类型C/C++运行时库及它的来龙去脉,这是C++开发中特别容易误入歧途的 ...

  8. Control Flow

    1.重写折半查找,使得在循环内部只执行一次测试 传统的非递归式的折半查找的例子中,while循环语句内部共执行了两次测试,其实只要一次就足够(代价是将更多的测试在循环外执行).重写该函数,使得在循环内 ...

  9. C# 窗体(登录界面)

    首先拖动一个  lable(写用户名)  后面 跟一个Textbox 再lable(写密码) 后面 跟一个Textbox(需设置一下属性—行为—useSystemPasswordChar(默认输入的密 ...

  10. objective-c第六章课后练习5

    题5:用于翻转从终端输入数的各个位.然后修改这个程序,以便正确的输入负数. code: ,result_5 = ; NSLog(@"input num_5:"); scanf(&q ...