Fish Weight

CodeForces - 297B

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

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

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的更多相关文章

随机推荐

  1. java——HashSet中add()方法不能加重复值得原因理解(我们一起来看底层代码吧)

    Set<String> names = new HashSet<>(); names.add("张三"); names.add(new String(&qu ...

  2. SQL的GROUP BY 与 Order By

    1.概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”,然后针对若干个“小区域”进行数据处理. 2.原始表 3.简 ...

  3. HBASE学习笔记(五)

    一.HBase的RowKey设计原则 1.我们知道HBase是三维有序存储的,通过RowKey(行键),ColumnKey(Column family和qualifier)和TimeStamp(时间戳 ...

  4. 1 sql server 利用多重赋值将一列的数据以逗号分隔,返回

    declare @mav varchar(max) select @mav=coalesce(@mav+', '+d.Name,d.Name) from ( select Name from Huma ...

  5. 能当壁纸用的Git常用命令速查表

    使用Microsoft Office 2016手工绘制. 链接: https://pan.baidu.com/s/18KsH-u5T2iSTHaXd6iQWGA 提取码: w8da 复制这段内容后打开 ...

  6. JavaJDBC【二、Mysql包加载与使用】

    连接数据库前提条件是: 1.加载mysql驱动 2.获取连接 加载驱动前需要将mysql的jar包引入项目 Demo: package JDBC; import java.sql.DriverMana ...

  7. deep_learning_CNN

    AI学习笔记——卷积神经网络(CNN) image.png 上篇文章简单地地介绍了神经网络和深度学习,在神经网络中,每一层的每个神经元都与下一层的每个神经元相连(如下图), 这种连接关系叫全连接(Fu ...

  8. 2.Java NIO 简介

    概述 Java NIO 是 JDK 1.4 发布的一套全新的IO API(New IO 简称 NIO),由于 JDK 1.7 对 NIO 的更新,目前 NIO 被广泛应用,以至于 将 JDK 1.7 ...

  9. Vim技巧----光标移动

    w:向前移动,光标停留在下个单词词首,每次一个单词(单词中不含其他字符如:- \ = +等) W:向前移动,光标停留在下个单词词首,每次一个字符串(字符串可以含有其字符如:- \ = +等,is-a ...

  10. Jmeter最佳录制工具BlazeMeter

    简介 在做接口测试时,开发会提供接口文档作为测试脚本编写的依据,但接口文档往往有一些局限性: 接口文档本身可能有编写错误 接口文档可以针对单个字段的取值和含义做描述,但多个字段的组合作用很难通过文字做 ...