Sum Game
Time limit1sMemory limit512 MB
Given two length-N sequences of daily scores, find the largest K where the prefix sums of both sequences are equal.
- Level
Easy3 of 10
- Topics
- Prefix sum, Array
- Solved
- No attempts yet
Problem
Annie has two favourite baseball teams, the Swifts and the Semaphores. She followed both of them through the season that just ended. The season lasted days, and each team played exactly one game every day.
For each day Annie wrote down how many runs the Swifts scored. She wrote down the same figure for the Semaphores.
She wants the largest integer with such that the Swifts and the Semaphores had scored the same total number of runs days after the start of the season. A team's total after days is the sum of the runs it scored in every game up to and including day .
For example, if the two teams have the same total at the end of the season, print . If the two teams never had the same total after games for any , print 0.
Input
The first line contains an integer ().
The second line contains space separated integers, the runs the Swifts scored on each day, in order.
The third line contains the runs the Semaphores scored on each day, in the same format.
Every score is a non-negative integer, and neither team scores more than 20 runs in a single game.
Output
Print on one line the largest integer with such that the Swifts and the Semaphores have the same total number of runs after days.
Hint
In the first example both teams had scored 4 runs after 2 days.
In the second example the only moment when the two totals matched was the start of the season.
In the third example the totals match after the first game, after the third game, and after the fourth game. The largest of those values, 4, is the answer.