• Bravebeart


    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.

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 
     5 using namespace std;
     6 
     7 int cmp(int a,int b){
     8     return a>b;
     9 }
    10 
    11 int main()
    12 {
    13     int t;
    14     int n;
    15     int w[50];
    16     int h[50];
    17     scanf("%d",&t);
    18     for(int j=0;j<t;j++){
    19         int bb=0;
    20         scanf("%d",&n);
    21         for(int i=0;i<n;i++){
    22             scanf("%d",&w[i]);
    23         }
    24         for(int i=0;i<n;i++){
    25             scanf("%d",&h[i]);
    26         }
    27         sort(w+1,w+n,cmp);
    28         sort(h,h+n);
    29         int braveheart=w[0]*h[n-1];
    30         for(int i=1;i<n;i++){
    31             if(w[i]*h[i-1]>=braveheart){
    32                 printf("NO
    ");
    33                 bb=1;
    34                 break;
    35             }
    36         }
    37         if(bb==1){
    38             continue;
    39         }
    40         printf("YES
    ");
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    09.安装Collabora Online服务
    08.nextcloud搭建
    07.安装及使用gitlub
    winmerge vs2010
    C#中时间计算汇总
    JS正则表达式大全 转
    js 验证正则
    js验证大全
    CSC 命令编译cs文件
    网站PV、UV以及查看方法(转)
  • 原文地址:https://www.cnblogs.com/TWS-YIFEI/p/6005939.html
Copyright © 2020-2023  润新知