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. Tika检测文件类型

    Tika类型检测 Tika支持MIME所提供的所有互联网媒体文件类型.每当一个文件通过Tika检测到该文件,其文件类型.检测的介质类型,Tika内部通过以下机制. MIME标准 多用途Internet ...

  2. STM32F10xxx_Keil中添加的预定义宏

    目录 STM32F10xxx_Keil中添加的预定义宏 更新记录 STM32F10xxx_Keil中添加的预定义宏 更新记录 version status description date autho ...

  3. JS中有两种自加法操作

    JS中有两种自加法操作.它们的运算符是++,它们的函数是向1添加运算符. 我和我的区别在于操作的顺序和组合的方向. 其中:++var被称为预自动添加,变量执行自动添加操作后.它的操作是先执行自动加法操 ...

  4. Rsyslog服务器的安装与配置

    一.Rsyslog服务器的安装与配置 1.清空iptabels, 关闭selinux避免安装过中报错 清空iptables iptables -F service iptables save 关闭se ...

  5. vue封装swiper

    参考:https://github.com/surmon-china/vue-awesome-swiper npm install vue-awesome-swiper --save 全局引入 imp ...

  6. MySQL四舍五入函数ROUND(x)、ROUND(x,y)和TRUNCATE(x,y)

    MySQL四舍五入函数ROUND(x) ROUND(x)函数返回最接近于参数x的整数,对x值进行四舍五入. 实例: 使用ROUND(x)函数对操作数进行四舍五入操作.SQL语句如下: mysql> ...

  7. centos8下jdk13和tomcat9的安装

    首先下载JDK13和tomcat9在对应的官网上: 通过xftp传到linux服务器上的对应的目录,如/usr/local  apache-tomcat-9.0.27.tar.gz ,jdk-13.0 ...

  8. vue 入门1 组件管理

    全局 组件.局部组件 // Vue.component('todo-list',{ // template:'<li >item</li>' // }); //全局 // va ...

  9. SQL语句复习【专题一】

    SQL语句复习[专题一] --创建用户 scott 并设置密码为 tiger create user scott identified by tiger --用户刚刚创建没有任何的权限,连登录的权限都 ...

  10. STM32 stm32fxxx_flash.icf文件的作用详解

    文章转载自:https://blog.csdn.net/weibo1230123/article/details/80142210 每个芯片开发商都会针对每款芯片来编写一个.icf文件就是传说中的链接 ...