E - Bravebeart

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

standard input/output
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

Input
2
6
12 9 7 1 20 10
3 6 4 7 5 5
4
5 17 10 1
200 400 800 600
Output
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的更多相关文章

  1. 2016-2017 CT S03E07: Codeforces Trainings Season 3 Episode 7

    B. Pen Pineapple Apple Pen Solved. 题意:将一个序列合并成一个数. 思路:分类讨论一下, 水. #include<bits/stdc++.h> using ...

随机推荐

  1. Convertion of grey code and binary 格雷码和二进制数之间的转换

    以下转换代码摘自维基百科 Wikipedia: /* The purpose of this function is to convert an unsigned binary number to r ...

  2. C语言编程实现Linux命令——who

    C语言编程实现Linux命令--who 实践分析过程 who命令是查询当前登录的每个用户,它的输出包括用户名.终端类型.登录日期及远程主机,在Linux系统中输入who命令输出如下: 我们先man一下 ...

  3. C#基础系列——再也不用担心面试官问我“事件”了

    前言:作为.Net攻城狮,你面试过程中是否遇到过这样的问题呢:什么是事件?事件和委托的区别?既然事件作为一种特殊的委托,那么它的优势如何体现?诸如此类...你是否也曾经被问到过?你又是否都答出来了呢? ...

  4. RTC时钟

    1.设置时间之前取消备份区域(BKP)写保护 主要有两部分组成 1.用来和APB1总线对接,对其进行读写操作 2. 预分频模块:在RTC_CR设置相应的允许,位每个TR_CLK周期中RTC产生一个中断 ...

  5. yii的验证码

    验证码比较麻烦,在三部分各有体现 controller <?php namespace app\controllers\demo_code; use yii\web\Controller; cl ...

  6. Jsoup 使用教程:输入

    使用背景: 使用网络爬虫(或者手动复制),从别的网站上下载下来的内容,都是一堆的html,很多标签.样式 等等都可能是你所不需要的,或者 想要变成你想要的样式.那么该怎么办呢? 我们知道,每一个网页都 ...

  7. Maven随记

    如何保持依赖的多个jar保持版本一致 在引入依赖的时候常常需要依赖多个独立的模块, 譬如Spring的content, aop等等, 为了保持版本一致, 可以设置<spring.version& ...

  8. 查询当前Database下所有Datatable及所有记录数

    DECLARE @TableName varchar(); CREATE TABLE #GetRecordingTempTable([id] [INT] IDENTITY(,) NOT NULL, [ ...

  9. Django简单的数据库操作

    当然,本篇的前提是你已经配置好了相关的环境,这里就不详细介绍. 一. 在settings.py文件中设置数据库属性. 如下: DATABASES = { 'default': { 'ENGINE': ...

  10. TP-LINK WR941 DD-WRT刷回OpenWRT及OpenWRT刷回原厂固件

    1.DD-Wrt 刷回 OpenWrt A.从官网下载固件: root@TL-DDWRT:/tmp# wget http://downloads.openwrt.org/barrier_breaker ...