CF1710E.Two Arrays
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays of integers a1,a2,…,an and b1,b2,…,bm .
Alice and Bob are going to play a game. Alice moves first and they take turns making a move.
They play on a grid of size n×m (a grid with n rows and m columns). Initially, there is a rook positioned on the first row and first column of the grid.
During her/his move, a player can do one of the following two operations:
- Move the rook to a different cell on the same row or the same column of the current cell. A player cannot move the rook to a cell that has been visited 1000 times before (i.e., the rook can stay in a certain cell at most 1000 times during the entire game). Note that the starting cell is considered to be visited once at the beginning of the game.
- End the game immediately with a score of ar+bc , where (r,c) is the current cell (i.e., the rook is on the r -th row and c -th column).
Bob wants to maximize the score while Alice wants to minimize it. If they both play this game optimally, what is the final score of the game?
输入格式
The first line contains two integers n and m ( 1≤n,m≤2⋅105 ) — the length of the arrays a and b (which coincide with the number of rows and columns of the grid).
The second line contains the n integers a1,a2,…,an ( 1≤ai≤5⋅108 ).
The third line contains the m integers b1,b2,…,bn ( 1≤bi≤5⋅108 ).
输出格式
Print a single line containing the final score of the game.
输入输出样例
输入#1
2 1 3 2 2
输出#1
4
输入#2
4 5 235499701 451218171 355604420 132973458 365049318 264083156 491406845 62875547 175951751
输出#2
531556171
说明/提示
In the first test case, Alice moves the rook to (2,1) and Bob moves the rook to (1,1) . This process will repeat for 999 times until finally, after Alice moves the rook, Bob cannot move it back to (1,1) because it has been visited 1000 times before. So the final score of the game is a2+b1=4 .
In the second test case, the final score of the game is a3+b5 .