codeforces A. TL 题解

Valera wanted to prepare a Codesecrof round. He‘s already got one problem and he wants to set a time limit (TL) on it.

Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong
solutions and for each wrong solution he knows its running time (in seconds).

Let‘s suppose that Valera will set v seconds TL in the problem. Then we can say that a solution passes the system testing if its running
time is at most v seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, a seconds,
an inequality 2a?≤?v holds.

As a result, Valera decided to set v seconds TL, that the following conditions are met:

  1. v is a positive integer;
  2. all correct solutions pass the system testing;
  3. at least one correct solution passes the system testing with some "extra" time;
  4. all wrong solutions do not pass the system testing;
  5. value v is minimum among all TLs, for which points 1, 2, 3, 4 hold.

Help Valera and find the most suitable TL or else state that such TL doesn‘t exist.

Input

The first line contains two integers nm (1?≤?n,?m?≤?100).
The second line contains n space-separated positive integers a1,?a2,?...,?an (1?≤?ai?≤?100)
— the running time of each of the n correct solutions in seconds. The third line contains m space-separated
positive integers b1,?b2,?...,?bm (1?≤?bi?≤?100)
— the running time of each of mwrong solutions in seconds.

Output

If there is a valid TL value, print it. Otherwise, print -1.

Sample test(s)

input

3 6
4 5 2
8 9 6 10 7 11

output

5

这句话难读懂:

We can also say that a solution passes the system testing with some "extra" time if for its running
time, a seconds,
an inequality 2a?≤?v holds.

就是说:如果一个AC的解决方案的运行时间是a,满足2*a <= v,那么就说这个运行时间通过而且有"extra"时间(a)

void TLjudge()
{
	int n, m, minVal = 1<<30, maxVal = 1<<31, a = 0;
	cin>>n>>m;
	while (n--)
	{
		cin>>a;
		if (a < minVal) minVal = a;
		if (a > maxVal) maxVal = a;
	}
	int ans = max(minVal*2, maxVal);
	bool ok = true;
	while (m--)
	{
		cin>>a;
		if (a <= ans)
		{
			ok = false;
			break;
		}
	}
	if (ok) cout<<ans;
	else cout<<-1;
};

codeforces A. TL 题解

时间: 2024-12-09 01:23:55

codeforces A. TL 题解的相关文章

codeforces Flipping Game 题解

Iahub got bored, so he invented a game to be played on paper. He writes n integers a1,?a2,?...,?an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1?≤?i?≤?j?≤?n) and flips all values 

codeforces The Wall - 题解

Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme o

codeforces Gravity Flip 题解

Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are n columns of toy cubes in the box arranged in a line. The i-th

Codeforces Unlucky Ticket 题解

Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you th

codeforces A. k-String 题解

A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string

codeforces A. Array题解

Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (?<?0). The product of all numbers in the secon

codeforces A. Cakeminator 题解

本题思路: 1 先扫描行,如果可以吃,就数吃了多少格,然后做好标志 2 扫描列,同样处理 扫描完就可以出答案了. 时间效率是O(n*m)了.算是暴力法 题目: http://codeforces.com/problemset/problem/330/A #include <vector> #include <algorithm> #include <utility> #include <string> #include <queue> #incl

Codeforces Amusing Joke 题解

So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name i

codeforces Epic Game 题解

Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of nstones. The players take turns to m