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. Leaf Sets CodeForces - 1042F (树,最小划分)

    大意: 给定树, 求叶子的最小划分, 使得每个划分内任意两个叶子距离不超过k. 任选一个非叶结点, 贪心合并. #include <iostream> #include <sstre ...

  2. asp.net 3.三层架构

    1.新建项目和类库 CZBK.ItcastProject (空白项目) CZBK.ItcastProject.BLL (类库) -- 逻辑业务 CZBK.ItcastProject.Common (类 ...

  3. unity 3D循环滚动效果

    https://blog.csdn.net/qinyuanpei/article/details/52765356 https://blog.csdn.net/chongzi_daima/articl ...

  4. 【原创】大叔经验分享(56)hue导出行数限制

    /opt/cloudera/parcels/CDH/lib/hue/apps/beeswax/src/beeswax/conf.py # Deprecated DOWNLOAD_CELL_LIMIT ...

  5. [转载]java的传值和传引用

    本文转载自:https://blog.csdn.net/weixin_36759405/article/details/82764339 基本类型(byte,short,int,long,double ...

  6. swagger2 Could not resolve pointer: /definitions

    错误信息: Errors Resolver error at paths././query.post.parameters.20.schema.$ref Could not resolve refer ...

  7. PHP敏感词替换

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8& ...

  8. DNS缓存失败怎么解决?

    DNS的中文名是域名系统,是域名和IP地址相互映射的一个分布式数据库.有了DNS,我们上网时直接输入网站域名(即网址)即可,而不用输入网站的IP地址访问网站,对于用户来说比较方便记忆和访问. 每次当我 ...

  9. ORA-01145: offline immediate disallowed unless media recovery enabled问题解决

    ORA-01145: offline immediate disallowed unless media recovery enabled (随记,后续整理) 数据库只有在归档模式下才能够直接对数据文 ...

  10. FlowNet2.0论文笔记

    原论文标题:FlowNet 2.0: Evolution of Optical Flow Estimation with Deep Networks 文章是对FlowNet的进一步改进,主要贡献为如下 ...