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 ...
随机推荐
-
[Spring]04_最小化Spring XML配置
4.1 自动装配 Bean Spring 装配 bean 时,有时非常明确,就是需要将某个 bean 的引用装配给指定属性. 例如,若应用上下文中只有一个 javax.sql.DataSource 类 ...
-
angularjs + fis +modJS 对于支持amd规范的组建处理(PhotoSwipe 支持,百度webUpload支持)
这不是很好的处理方式,但是能够解决问题,希望有大神推荐更好的方式. 前端模块使用angularjs + fis +modJS 开发前端应用有两个月了.总结了以下的优点: fis 自动构建,自动发布,功 ...
-
Codeforces Round #208 (Div. 2) A.Dima and Continuous Line
#include <iostream> #include <algorithm> #include <vector> using namespace std; in ...
-
javascript之正则表达式总结
了解RegExp类型: ECMAScript通过RegExp类型来支持正则表达式. var expression=/pattern/flags; 正则表达式的模式(pattern)部分: 可以是任何简 ...
-
物联网操作系统 - Contiki
What is Contiki? Contiki is an open source operating system for the Internet of Things. Contiki conn ...
-
shadow projection
1.概述 shadow projection,又可成为planar shadow, 这是一种非常简单的绘制阴影的方法. 主要应用的应用场景:物体在平面投射阴影. 主要思想:把阴影看作是物体在平面上的投 ...
-
AngularJS 初学笔记(理论基础)
AngularJS 是一个 JavaScript 框架.它是一个以 JavaScript 编写的库. AngularJS 通过 ng-directives 扩展了 HTML. ng-app 指令定义一 ...
-
JavaSE基础问答
1.JAVA的基本数据类型有哪些? JAVA的基本数据类型分为4类8种,就是整形 byte.short.int.long.浮点型 float 跟double,字符型 char,跟布尔型 true和 f ...
-
Android--逐帧动画FrameAnimation
前言 开门见山,本篇博客讲解一下如何在Android平台下播放一个逐帧动画.逐帧动画在Android下可以通过代码和XML文件两种方式定义,本篇博客都将讲到,最后将以一个简单的Demo来演示两种方式定 ...
-
【Hadoop】3、Hadoop-MapReduce使用avro进行数据的序列化与反序列化
package cn.cutter.demo.hadoop.avro; import org.apache.hadoop.io.Text; import java.text.DateFormat; i ...