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. LeetCode:Multiply Strings

    题目链接 Given two numbers represented as strings, return multiplication of the numbers as a string. Not ...

  2. Redis作为消息队列服务场景应用案例

    NoSQL初探之人人都爱Redis:(3)使用Redis作为消息队列服务场景应用案例   一.消息队列场景简介 “消息”是在两台计算机间传送的数据单位.消息可以非常简单,例如只包含文本字符串:也可以更 ...

  3. NOSQL数据模型和CAP原理

    NOSQL数据模型和CAP原理 http://blog.sina.com.cn/s/blog_7800d9210100t33v.html 我本来一直觉得NoSQL其实很容易理解的,我本身也已经对NoS ...

  4. cookie被禁用session怎么办

    关闭Cookie的情况下使用Session,途径有以下几种:\ 1. 设置php.ini配置文件中的“session.use_trans_sid = 1”,或者编译时打开“--enable-trans ...

  5. JavaScript之命名空间模式 浅析

    来源于:http://www.cnblogs.com/syfwhu/p/4885628.html 前言 命名空间可以被认为是唯一标识符下代码的逻辑分组.为什么会出现命名空间这一概念呢?因为可用的单词数 ...

  6. 初步搭建RocketMQ环境

    1. 去官网https://github.com/alibaba/RocketMQ/releases下载alibaba-rocketmq-3.2.6.tar.gz,这个是已经maven install ...

  7. git版本控制?

    git是一个分布式的版本控制系统,版本控制系统,类似于保险箱,而我们的代码就是资产:通过对代码的有效管理可以更好的提高我们的生产效率:maven是主要是一个项目构建工具,解决的是我们个人在开发过程中的 ...

  8. 11月14日用AJAX、PHP、SESSION做购物车

    购物车网页代码 1.登录界面login.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  9. getResourceAsStream和getResource的用法及Demo实例

    用JAVA获取文件,听似简单,但对于很多像我这样的新人来说,还是掌握颇浅,用起来感觉颇深,大家最经常用的,就是用JAVA的File类,如要取得 D:/test.txt文件,就会这样用File file ...

  10. Centos6.5 Zabbix3 server端安装(一)

    一.准备阶段: 1.>关闭防火墙 /etc/init.d/iptables stop 2.>关闭selinux vim /etc/selinux/config SELINUX=disabl ...