Game
시간 제한2초메모리 제한512 MB
격자 상태에서 두 플레이어가 번갈아 이동하며 언제든 게임을 끝낼 수 있을 때, 완벽한 플레이로 얻는 최종 점수를 구한다.
문제
There are two arrays of integers and of length and , respectively.
There is a chosen position in each array. Denote the chosen position in as and in as . The state is a tuple (). The chosen positions are never out of bounds, i.e. and . At the start of the game both and are equal to .
Two players are playing a game taking turns alternately. On his turn each player must do one of the following:
- Move. Change the chosen position in one of the arrays. You can't change a chosen position to itself. It is not allowed to make a move which will result in a state appearing for the -th time. The starting state is considered as having appeared once at the beginning of the game.
- Screw you guys, I'm going home. Finish the game.
Note that there are states and each state appears no more than times. Therefore the game is finite.
The score of the game is equal to the sum of elements on the chosen positions, i.e. . The player who moves first minimizes it by playing accordingly and the one who moves second maximizes it.
What is the score of the game assuming perfect play from both sides?
입력
The first line contains two and (), lengths of arrays and , respectively.
The second line contains integers (), the elements of .
The third line contains integers (), the elements of .
출력
Output a single integer --- the score of the game.