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的更多相关文章
随机推荐
- 修改mac系统的host文件 (一)
hosts是本地预先配置的DNS数据,解析域名的时候首先试图从hosts文件获取,没有则从DNS服务器获取. 此文件的三个主要用途: 加快域名解析 方便局域网用户 一般局域网很少假设DNS服务器,访问 ...
- CentOS7 yum安装Mariadb
1.安装Mariadb #yum -y install mariadb mariadb-server 1.1当执行程序末端显示Complete则完成安装 2.安装完成后启动服务 # systemctl ...
- O051、Create Volume 操作 (Part II)
参考https://www.cnblogs.com/CloudMan6/p/5612147.html 1.cinder-scheduler 也会启动一个工作流 volume_create_ ...
- python爬虫redis-ip代理池搭建几十万的ip数据--可以使用
from bs4 import BeautifulSoupimport requests,os,sys,time,random,redisfrom lxml import etreeconn = re ...
- jdbc原生操作数据库
jdbc原生操作数据库流程: 第一步:Class.forName()加载数据库连接驱动: 第二步:DriverManager.getConnection()获取数据连接对象; 第三步:根据 SQL 获 ...
- sqlserver关于发布订阅replication_subscription的总结
(转载)sqlserver关于发布订阅replication_subscription的总结 来自 “ ITPUB博客 ” ,原文地址:http://blog.itpub.net/30126024/v ...
- centos7 开放/关闭防火墙和端口
--------------------------------------------------------------防火墙----------------------------------- ...
- 基于MQTT的串口数据转发器
问: ComHub能做什么?ComHub使用MQTT协议,将串口数据经TCP分发出去.这种结构可以实现很多功能:1.COM-Over-TCP: 将COM数据使用TCP远程传送;2.COM多播:一个CO ...
- 【转】vm ubuntu14.04 建立共享文件夹
第一步:启动Ubuntu 14.04(其他版本的Ubuntu操作差不多) 1. 在VMware虚拟机界面,点VM->Install VMware Tools.之后,显示如下图: ...
- 【转】__cplusplus的含义
有点代码中会看到以下形式的代码: #ifdef __cplusplus extern "C" {#endif #ifdef __cplusplus}#endif 这些代码是什么意思 ...