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
  1. 3 3 3
    2 2 2
    1 1 3
Output
  1. YES
Input
  1. 4 7 9
    5 2 7 3
    3 5 2 7 3 8 7
Output
  1. 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了

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef int ll;
  4. inline ll read()
  5. {
  6. ll s=;
  7. bool f=;
  8. char ch=' ';
  9. while(!isdigit(ch))
  10. {
  11. f|=(ch=='-'); ch=getchar();
  12. }
  13. while(isdigit(ch))
  14. {
  15. s=(s<<)+(s<<)+(ch^); ch=getchar();
  16. }
  17. return (f)?(-s):(s);
  18. }
  19. #define R(x) x=read()
  20. inline void write(ll x)
  21. {
  22. if(x<)
  23. {
  24. putchar('-'); x=-x;
  25. }
  26. if(x<)
  27. {
  28. putchar(x+''); return;
  29. }
  30. write(x/);
  31. putchar((x%)+'');
  32. return;
  33. }
  34. #define W(x) write(x),putchar(' ')
  35. #define Wl(x) write(x),putchar('\n')
  36. const int N=;
  37. int n,m,K,a[N],b[N],Hash[N<<];
  38. int main()
  39. {
  40. int i;
  41. R(n); R(m); R(K);
  42. for(i=;i<=n;i++) Hash[++*Hash]=(a[i]=read());
  43. for(i=;i<=m;i++) Hash[++*Hash]=(b[i]=read());
  44. sort(Hash+,Hash+*Hash+);
  45. *Hash=unique(Hash+,Hash+*Hash+)-Hash-;
  46. for(i=;i<=n;i++) a[i]=lower_bound(Hash+,Hash+*Hash+,a[i])-Hash;
  47. for(i=;i<=m;i++) b[i]=lower_bound(Hash+,Hash+*Hash+,b[i])-Hash;
  48. sort(a+,a+n+);
  49. sort(b+,b+m+);
  50. int Now=m+;
  51. for(i=n;i>=;i--)
  52. {
  53. while(Now>&&b[Now-]>=a[i]) Now--;
  54. if(n-i+>m-Now+) return puts("YES"),;
  55. }
  56. puts("NO");
  57. return ;
  58. }
  59. /*
  60. Input
  61. 3 3 3
  62. 2 2 2
  63. 1 1 3
  64. Output
  65. YES
  66.  
  67. Input
  68. 4 7 9
  69. 5 2 7 3
  70. 3 5 2 7 3 8 7
  71. Output
  72. NO
  73. */

codeforces297B的更多相关文章

随机推荐

  1. Jmeter安装及配置(含JDK安装)

    (一)java环境配置1.官网下载64位的jdkhttp://www.oracle.com/technetwork/java/javase/downloads/index.html 2.环境变量设置变 ...

  2. C#委托的定义 以及使用方式详解,更简单的理解委托。

    委托的声明及定义: 委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递,这种将方法动态地赋给参数的做法,可以避免在程序中大量使用If-Else(Switch)语句,同时使得 ...

  3. URL的 ? 和 # (hash),如何将参数保存在URL中,用于刷新获取之前的变量?

    URL中会带上参数,假如是?开头的,那这个是会被加入到ajax请求中的,#(hash)相当于书签锚点,用于定位页面,不会加入到ajax请求中,所以有些时候,我们可以把一些参数放在#后面 如何获取URL ...

  4. java 将一个正整数翻译成人民币大写的读法

    程序如下: import java.lang.StringBuffer; /** 给定一个浮点数,将其装换成人民币大写的读法 88.5:捌十捌元零伍角 */ public class Num2Rmb ...

  5. linux环境下,springboot jar启动方式

    linux环境下,springboot jar启动方式 一.前台启动(ctrl+c会关掉进程) java -jar application.jar 二.后台启动(ctrl+c不会关闭) java -j ...

  6. python转化13位时间戳

    # -*- coding: utf-8 -*- def get_time_stamp13(datetime_obj): import datetime, time # 生成13时间戳 eg:15578 ...

  7. Java学习笔记【十一、序列化】

    序列化的条件 实现Serializable接口 所有属性必须是可序列化的,或标记为transient(不做序列化) 序列化-将对象输出为序列化文件 ObjectOutputStream 反序列化-将序 ...

  8. ZooKeeper--动物管理员

    复杂的软件集群系统从来绕不开高可用.负载均衡等问题,大数据系统更是如此. 高可用:计算机系统的可用性定义为系统保持正常运行时间的百分比,具体手段有自动检测,自动切换,自动恢复等. 负载均衡:主要解决单 ...

  9. 怎么提高U盘传输文件的性能?

    U盘使用时间久了,其传输复制文件速度就可能会变得有些慢.出现这个问题的原因有很多,除了U盘本身的问题外,也可能会有电脑设置方面的因素在影响.好系统下面就来告诉大家解决U盘传输复制文件速度慢的几个小技巧 ...

  10. yocto 编译C程序

    1. 找到编译器位置所在(相关设置参考/opt/poky/1.7/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi文件) poky安装在 ...