Gym 101138E Bravebeart【水题】

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 warrior w1, 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 6335560 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.



/*
    题意:给定两个序列w[i]和h[i],w[i]表示每个战士的力量,h[i]表示每匹马的力量
          每个战士都必须配一匹马,每个战士的冲锋值=w[i]*h[i],现在要求你确认是
          否存在w[1]找一匹马使得他的冲锋值严格大于你给其他战士找一匹马的冲锋值
    类型:水题
    分析:先给w[1]找一匹力量最大的马,然后把其他战士和其他马的力量值排下序,贪心
          最大力量的战士配最小力量的马,然后判断一下就行了
*/
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 50;
int a[maxn],b[maxn];
bool cmp(const int &a,const int &b){
    return a>b;
}
int main()
{
    int t;cin>>t;
    while(t--){
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        for(int i=0;i<n;i++){
            scanf("%d",&b[i]);
        }
        sort(a+1,a+n);
        sort(b,b+n,cmp);
        int tmp=a[0]*b[0];
        int flag=0;
        for(int i=1;i<n;i++){
            if(a[i]*b[i]>=tmp){
                flag=1;break;
            }
        }
        if(flag)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值