codeforces297B
Fish Weight
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds.
Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight?
Input
The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species.
The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob.
Note that one may have caught more than one fish for a same species.
Output
Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise.
Examples
3 3 3
2 2 2
1 1 3
YES
4 7 9
5 2 7 3
3 5 2 7 3 8 7
NO
Note
In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6weight units, while Bob only has 1 + 1 + 2.5 = 4.5.
In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish.
sol:贪心乱搞,先后后缀和只要个数大于另一个就是YES了
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,K,a[N],b[N],Hash[N<<];
int main()
{
int i;
R(n); R(m); R(K);
for(i=;i<=n;i++) Hash[++*Hash]=(a[i]=read());
for(i=;i<=m;i++) Hash[++*Hash]=(b[i]=read());
sort(Hash+,Hash+*Hash+);
*Hash=unique(Hash+,Hash+*Hash+)-Hash-;
for(i=;i<=n;i++) a[i]=lower_bound(Hash+,Hash+*Hash+,a[i])-Hash;
for(i=;i<=m;i++) b[i]=lower_bound(Hash+,Hash+*Hash+,b[i])-Hash;
sort(a+,a+n+);
sort(b+,b+m+);
int Now=m+;
for(i=n;i>=;i--)
{
while(Now>&&b[Now-]>=a[i]) Now--;
if(n-i+>m-Now+) return puts("YES"),;
}
puts("NO");
return ;
}
/*
Input
3 3 3
2 2 2
1 1 3
Output
YES Input
4 7 9
5 2 7 3
3 5 2 7 3 8 7
Output
NO
*/
codeforces297B的更多相关文章
随机推荐
- Docker——入门
虚拟化最大区别:虚拟化技术元件,资源申请调度到其他硬件服务器: Docker是一个开源得应用容器引擎,让开发者可以打包他们得应用以及依赖包到一共可移植得容器中,然后发布到任何流行得linux机器上,也 ...
- 史上最全的spark面试题——持续更新中
史上最全的spark面试题——持续更新中 2018年09月09日 16:34:10 为了九亿少女的期待 阅读数 13696更多 分类专栏: Spark 面试题 版权声明:本文为博主原创文章,遵循C ...
- DVWA之SQL注入演练(low)
1.设置 把安全等级先调整为low,让自己获得点信心,免得一来就被打脸. 2.测试和分析页面的功能 这里有一个输入框 根据上面的提示,输入用户的id.然后我们输入之后,发现它返回了关于这个 ...
- 怎样禁止 html 中 <textarea> 标签可以拉伸改变大小 ?
1. 一般来说, 使用 <textarea> 这个标签都会禁用掉它的这个默认属性, 不然可能会被用户玩儿坏, 而且也不利于其他元素的展示, 使用到的属性是 resize , 改为 none ...
- centos7上搭建NFS的实践
NFS 即network file system 可用于向k8s集群提供持久存储 最小化安装centos后 把网卡设置好了后 1.关闭防火墙 [root@NFS ~]# systemctl stop ...
- 13 Django之中间件
一.什么是中间件 中间件顾名思义,是介于request与response处理之间的一道处理过程,相对比较轻量级,并且在全局上改变django的输入与输出.因为改变的是全局,所以需要谨慎实用,用不好会影 ...
- css————关于margin:0px auto的几个居中问题
前言 margin:0px auto;适用于指定了固定宽度的div与其它元素,比如p,img等,使用 margin:0px auto,居中是大家在做css div定位时的最常用方法,但是据我自己的使用 ...
- JS中有两种自加法操作
JS中有两种自加法操作.它们的运算符是++,它们的函数是向1添加运算符. 我和我的区别在于操作的顺序和组合的方向. 其中:++var被称为预自动添加,变量执行自动添加操作后.它的操作是先执行自动加法操 ...
- vue.js项目开发实战笔记001——准备工作
1,Vue.js 是一套构建用户界面的渐进式框架. 2,Vue.js 是由尤雨溪开发出的,最早发布于2014年2月. 3,引用vue.js地址一CDN: <script src="ht ...
- require.context() 用于获取一个特定上下文的,webpack的一个api
参考链接: 1.https://www.jianshu.com/p/c894ea00dfec 2.https://www.jianshu.com/p/c894ea00dfec require.cont ...