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的更多相关文章
随机推荐
- Jmeter安装及配置(含JDK安装)
(一)java环境配置1.官网下载64位的jdkhttp://www.oracle.com/technetwork/java/javase/downloads/index.html 2.环境变量设置变 ...
- C#委托的定义 以及使用方式详解,更简单的理解委托。
委托的声明及定义: 委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递,这种将方法动态地赋给参数的做法,可以避免在程序中大量使用If-Else(Switch)语句,同时使得 ...
- URL的 ? 和 # (hash),如何将参数保存在URL中,用于刷新获取之前的变量?
URL中会带上参数,假如是?开头的,那这个是会被加入到ajax请求中的,#(hash)相当于书签锚点,用于定位页面,不会加入到ajax请求中,所以有些时候,我们可以把一些参数放在#后面 如何获取URL ...
- java 将一个正整数翻译成人民币大写的读法
程序如下: import java.lang.StringBuffer; /** 给定一个浮点数,将其装换成人民币大写的读法 88.5:捌十捌元零伍角 */ public class Num2Rmb ...
- linux环境下,springboot jar启动方式
linux环境下,springboot jar启动方式 一.前台启动(ctrl+c会关掉进程) java -jar application.jar 二.后台启动(ctrl+c不会关闭) java -j ...
- python转化13位时间戳
# -*- coding: utf-8 -*- def get_time_stamp13(datetime_obj): import datetime, time # 生成13时间戳 eg:15578 ...
- Java学习笔记【十一、序列化】
序列化的条件 实现Serializable接口 所有属性必须是可序列化的,或标记为transient(不做序列化) 序列化-将对象输出为序列化文件 ObjectOutputStream 反序列化-将序 ...
- ZooKeeper--动物管理员
复杂的软件集群系统从来绕不开高可用.负载均衡等问题,大数据系统更是如此. 高可用:计算机系统的可用性定义为系统保持正常运行时间的百分比,具体手段有自动检测,自动切换,自动恢复等. 负载均衡:主要解决单 ...
- 怎么提高U盘传输文件的性能?
U盘使用时间久了,其传输复制文件速度就可能会变得有些慢.出现这个问题的原因有很多,除了U盘本身的问题外,也可能会有电脑设置方面的因素在影响.好系统下面就来告诉大家解决U盘传输复制文件速度慢的几个小技巧 ...
- yocto 编译C程序
1. 找到编译器位置所在(相关设置参考/opt/poky/1.7/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi文件) poky安装在 ...