Bravebeart
Description
Statements
Would you want to fight against bears riding horses? Me neither.
Limak is a grizzly bear. He is a general of the dreadful army of Bearland. The most important part of an army is the cavalry of course.
The cavalry of Bearland consists of n warriors and n horses, both numbered 1 through n. Limak knows the strength of each warriorw1, w2, ..., wn and of each horse h1, h2, ..., hn.
A warrior together with his horse is called a unit. The strength of a unit is equal to the multiplied strengths of a warrior and a horse.
General Limak must assign all horses to warriors, one horse per warrior. The cavalry will consist of n units then.
The first warrior (the one with the strength w1) is called Bravebeart. He is always the first to charge the enemy. Limak decided that Bravebeart deserves some respect and his unit must be the strongest one, with no ties allowed. But is it possible?
Help Limak and check whether there is an assignment of horses to warriors for which the Bravebeart's unit is strictly stronger than any other unit. Print "YES" or "NO" (without the quotes).
Input
You are given multiple test cases.
The first line of the input contains one integer T (1 ≤ T ≤ 50), denoting the number of test cases.
For each test case the first line contains one integer n (2 ≤ n ≤ 42).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 1000), denoting strengths of warriors. The first number is the strength of Bravebeart.
The third line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 1000), denoting strengths of horses.
Output
For each test case find the answer and print it in a separate line.
Print "YES" (without the quotes) if there is an assignment where the strength of the Bravebeart's unit is strictly greater than strength of any other unit. Otherwise print "NO" (without the quotes).
Sample Input
2
6
12 9 7 1 20 10
3 6 4 7 5 5
4
5 17 10 1
200 400 800 600
YES
NO
Hint
In the first test case Bravebeart can take a horse of strength 6 to get the unit strength 12·6 = 72.
In one way of assigning other horses to warriors the pairs (strength of warrior, strength of horse) are: (9, 7), (7, 5), (1, 5), (20, 3),(10, 4). Units strengths would be 63, 35, 5, 60 and 40, respectively. Indeed, the Bravebeart's unit is stronger than any other unit then.
In the second test case it's impossible to assign horses to warriors so that Bravebeart's unit is stronger than any other one.
#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std; int cmp(int a,int b){
return a>b;
} int main()
{
int t;
int n;
int w[];
int h[];
scanf("%d",&t);
for(int j=;j<t;j++){
int bb=;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&w[i]);
}
for(int i=;i<n;i++){
scanf("%d",&h[i]);
}
sort(w+,w+n,cmp);
sort(h,h+n);
int braveheart=w[]*h[n-];
for(int i=;i<n;i++){
if(w[i]*h[i-]>=braveheart){
printf("NO\n");
bb=;
break;
}
}
if(bb==){
continue;
}
printf("YES\n");
}
return ;
}
Bravebeart的更多相关文章
- 2016-2017 CT S03E07: Codeforces Trainings Season 3 Episode 7
B. Pen Pineapple Apple Pen Solved. 题意:将一个序列合并成一个数. 思路:分类讨论一下, 水. #include<bits/stdc++.h> using ...
随机推荐
- MD测试
# 欢迎使用 Cmd - 在线 Markdown 编辑阅读器 ------ 我们理解您需要更便捷更高效的工具记录思想,整理笔记.知识,并将其中承载的价值传播给他人,**Cmd Markdown** 是 ...
- 如何通过ShadowSocket自动更新Chrome
经常收到Chrome的更新提示,并下载更新程序后,报无法连接网络,然后更新不能了, 经过一段时间的搜索,找到了一条比较好的方法,分享一下: 1. 本机打开ShadowSocket 2. 打开Privo ...
- VSS每次打开都需要服务器账号和密码的解决方法
最近在做的一个项目还在使用非常非常古老的VSS(Microsoft Visual SourceSafe)2005,是的,没有看错,是VSS2005,而不是Git或是SVN.然后我的VSS在安装过后遇到 ...
- 可变长子网掩码 VLSM
2014-05-05 17:26:08 标签:IP地址 路由器 技术部 路由表 长子 VLSM的介绍: VLSM(VLSM(Variable Length Subnetwork Mask,可变长子网掩 ...
- 【Beta版本】七天冲刺——日志集合贴
No Bug 031402401鲍亮 031402402曹鑫杰 031402403常松 031402412林淋 031402418汪培侨 031402426许秋鑫 Day1 Day2 Day3 Day ...
- HTTP协议(二):header标头说明
Header 解释 示例 Accept-Ranges 表明服务器是否支持指定范围请求及哪种类型的分段请求 Accept-Ranges: bytes Age 从原始服务器到代理缓存形成的估算时间(以秒计 ...
- 开发haproxy管理平台
1.说明:该脚本仅适用于Linux操作系统2.使用方法: 在该脚本同级目录下要创建一个名字叫做 haproxy 的文件 haproxy 文件内容如下 global log 127.0.0.1 loca ...
- 一些js 插件的作用
前言: 从一些开源网站上下载下来的 后台管理系统模板一般会有很多的js ,其js 的功能是什么呢?这里随手查询了一下,记录下来 正文: 1.zDialog.js 各种弹窗插件详细案例:http://w ...
- ReactNative 从环境和第一个demo说起,填坑教程
一.React-Native MacOS必备环境配置: 1.安装homebrew(这东西可以理解为命令行的app商店) /usr/bin/ruby -e "$(curl -fsSL http ...
- Jquery的 each的使用 $.each()
下面提一下each的几种常用的用法 1.each处理一维数组 var arr1 = [ "aaa", "bbb", "ccc" ]; $.e ...