Fish Game
Time limit1sMemory limit1024 MB
Otto and Dave alternate moves on a 2xN grid, each taking the fish in every cell they enter; find what each takes under optimal play.
- Level
Medium7 of 10
- Topics
- Game theory, Prefix sum, Greedy
- Solved
- No attempts yet
Problem
Otto received curry with conger eel in Hanchosu, and in return he built Dave a fish farm of size !

- Dave: Oh...! What is this place?
- Otto: You have been struggling to catch fish every day, haven't you?
- Otto: So I built this fish farm in a single day yesterday!
- Dave: ... In a single day?
- Otto: First, I put fish in each cell except and .
- Otto: But I cannot just give them to you. Play a game with me, and I will give you as many fish as you earn!
So Dave and Otto began a game. Otto stands at , and Dave stands at . Every cell except and contains fish. Dave and Otto repeat the following turns times.
- Otto moves to an adjacent cell.
- Otto harvests all fish in that cell and takes them. The fish do not regrow after Otto leaves the cell.
- Dave moves to an adjacent cell.
- Dave harvests all fish in that cell and takes them. The fish do not regrow after Dave leaves the cell.
- Dave and Otto may be in the same cell at the same time.
Both Dave and Otto try to take as many fish as possible. Find the number of fish Otto takes and the number of fish Dave takes.
Input
The first line contains the size of the fish farm .
The second line contains , separated by spaces.
The third line contains , separated by spaces.
Output
When both play optimally, print the number of fish Otto takes and the number of fish Dave takes, separated by a space.
Constraints
- When ,
- All given numbers are integers.