WOSS Dual Olympiad 2022 Team Round P2: Bobby's Studying Schedule

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 256M

Problem types

After getting his integration test successfully delayed by N days, Bobby wants to create a schedule to study. He checks his calendar and realizes that on the ith day, he has t_i hours available to study. However, Bobby is weird and wants to study for exactly a multiple of k hours each day, where k cannot equal 1. For example, if k = 3, Bobby could only study for 3, 6, 9, 12, \dots, 21 or 24 hours on any particular day as long as that number is less than t_i. Find the most amount of hours Bobby can study given his schedule, for an optimal k value.


1 \le N \le 2 \times 10^5

1 \le t_i \le 24

Input Specification

The first line will contain a single integer, N, giving the number of days Bobby has to study.

The second line will contain N space-separated integers, with the ith integer being the value t_i, or the amount of study time Bobby has available on the ith day.

Output Specification

Output should consist of a single line, containing a single integer: the maximum amount of hours Bobby can study with an optimal k value.

Sample Input 1

5 10 15 5 6

Sample Output 1


Explanation of Sample 1

In this case, it is optimal to choose k = 5. This means that on any given day i, Bobby must study for a number of hours that is a multiple of 5, but is less than or equal to t_i. On day one, Bobby studies for 5 hours. On day two he studies for 10 hours. On day three he studies for 15 hours. On day four he studies for 5 hours. On day five he studies for 5 hours. This yields a total of 40 hours.

Sample Input 2

24 23 24 24 23 17 15 24 24 24

Sample Output 2



There are no comments at the moment.