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 ...
随机推荐
- Macbook被格式化之后
macbook不小心被手贱格式化了,开机显示一个大问号. 于是查询得到恢复方式是使用command+R. 照做了,试了好几次,那个地球还是卡住不动的.都没有提示让我输入wifi密码. 于是又查了一下, ...
- 【技术贴】大型发布会现场的WiFi网络应该如何搭建?
WiFi网络的部署要远远比一般人想象的复杂,不是说放上几十个AP带宽就自动增加几十倍,恰恰相反,简单放几十个AP带宽会由于AP之间的竞争而 迅速使带宽下降为几乎不可用.实际上这个问题完全可以写一本书了 ...
- pagerank
http://jung.sourceforge.net/ https://github.com/louridas/pagerank/blob/aeb9b17ada1f925bb525961574f6d ...
- HTTP原型
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- 创建一个新的Activity
1.创建一个类继承Activity类,并创建对应的布局文件,在onCreate方法中加载该布局. 2.在AndroidManifest.xml声明该组件 注:如果想配置一个activity在桌面上有该 ...
- UIDynamic(简单介绍)
一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟和仿真现实生活中的物理现象 如:重力.弹性碰撞等现 ...
- 【BZOJ-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
- 没有为 COM 互操作注册程序集 请使用 regasm.exe /tlb 注册该程序集——解决办法
错误现象: 错误 6 没有为 COM 互操作注册程序集“DevExpress.Utils.v13.1, Version=13.1.7.0, Culture=neutral, PublicKeyToke ...
- python3随记——字符编码
1.1什么是字节 字节(Byte)是计算机信息技术用于计量存储容量的一种计量单位,也表示一些计算机编程语言中的数据类型和语言字符. 比特(bit)在计算机中最小的单位,在二进制位的电脑的系统中,每一b ...
- 如何学习Oracle
如何学习Oracle?分清几个概念是关键 经常有一些Oracle的初学者问到以下几个问题,这里集中解答一下,希望对大家有帮助. 1.如果有一定的数据库基础,知道SQL是怎么回事,即使写不出 ...