## CCC '17 S1 - Sum Game

View as PDF

Points: 3
Time limit: 1.0s
Memory limit: 256M

Problem type
##### Canadian Computing Competition: 2017 Stage 1, Senior #1

Annie has two favourite baseball teams: the Swifts and the Semaphores. She has followed them throughout the season, which is now over. The season lasted for days. Both teams played exactly one game on each day.

For each day, Annie recorded the number of runs scored by the Swifts on that day. She also recorded this information for the Semaphores.

She would like you to determine the largest integer such that and the Swifts and the Semaphores had scored the same total number of runs days after the start of the season. The total number of runs scored by a team after days is the sum of the number of runs scored by the team in all games before or on the -th day.

For example, if the Swifts and the Semaphores have the same total number of runs at the end of the season, then you should output . If the Swifts and the Semaphores never had the same number of runs after games, for any value of , then output 0.

#### Input Specification

The first line of input will contain an integer . The second line will contain space-separated non-negative integers representing the number of runs scored by the Swifts on each day, in order. The third line will contain space-separated non-negative integers representing the number of runs scored by the Semaphores on each day, in order. You may assume that each team scored at most runs in any single game.

For 7 of the 15 points available, .

#### Output Specification

Output the largest integer such that and the Swifts and the Semaphores have the same total number of runs after days.

#### Sample Input 1

3
1 3 3
2 2 6

#### Sample Output 1

2

#### Explanation for Sample Output 1

After 2 days, each team had scored a total of 4 runs.

#### Sample Input 2

3
1 2 3
4 5 6

#### Sample Output 2

0

#### Explanation for Sample Output 2

The only time when the Swifts and the Semaphores had scored the same number of runs was at the beginning of the season.

#### Sample Input 3

4
1 2 3 4
1 3 2 4

#### Sample Output 3

4

#### Explanation for Sample Output 3

The Swifts and Semaphores have the same number of total runs after the first game, and after the third game, and after the fourth game. We take the largest of these values (1, 3 and 4) and output 4.

• commented on Jan. 8, 2024, 12:24 a.m.

This really made me have to rack my brain but it's very cool ;

• commented on Dec. 17, 2023, 11:24 p.m.

should the input be a string in c ?

• commented on July 23, 2022, 11:23 p.m.

Anyone know why my solution doesn't work? https://dmoj.ca/src/4717382

• commented on June 12, 2022, 2:41 p.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Aug. 8, 2021, 4:38 p.m.

can anyone tell me why my code won't work?

• commented on Aug. 8, 2021, 6:58 p.m. edit 4

put if(S == S1) outside of the nested for loop. In your code, if r == 0 but S == S1, it will also be added to preK which is incorrect

If you try the following

2
1 2
3 4

your code will print 2, but the correct output should be 0

• commented on Aug. 8, 2021, 7:10 p.m.

Thank you! My code works now. :D

• commented on Dec. 14, 2019, 4:49 a.m.

TLE in python3. Can someone hint what I should be doing to avoid this? Thanks.

• commented on Nov. 21, 2021, 6:59 p.m.

Keep a running count instead of re-computing the number of runs every time.

• commented on Jan. 6, 2019, 2:45 p.m. edited

I can't get test case 3 in batch 1 in java. Someone help`pls

• commented on Jan. 6, 2019, 11:06 p.m.

i checked your code with java 8, it works, in the language section, just choose java 8 and you should get full AC

• commented on Jan. 6, 2019, 9:48 p.m.

I don't see anything wrong with your code, so I would suggest trying java 8 as well because java 8 should be a bit faster than java 9(I think). Submit a few times as well, because the judges do not always have consistent times so you may exceed the time limit with the code, but pass on another time. And, if all fails, consider learning how to used BufferedReader.

• commented on Oct. 7, 2018, 2:20 a.m.

If you're getting a TLE in java, make sure you use a buffered reader.