Stone Skipping (SUJEBI)
InterviewTime limit2sMemory limit512 MB
For each step size d, sum the cells at multiples of d and pick the d with the largest sum, printing 0 0 if that sum is not positive.
- Level
Medium5 of 10
- Topics
- Math, Brute force, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
A sharp change in the climate let invasive species spread through many rivers of Daegwak. The government discussed the problem and settled on the Flat Dumpling Plan: skip a stone across a river and wipe out the invasive species in the cells the stone touches.
The river picked for the plan has width , and the river is modeled as consecutive cells numbered 1 through . The environment ministry scored every cell by how dangerous the species living there is. Some cells hold native species, so a score can be negative.
Throwing two or more stones makes your arm hurt, so exactly one stone is thrown. Depending on the power of the throw, the stone bounces at a fixed interval (), passing over cell , then cell , and so on up to cell . Find the natural number that maximizes the sum of the scores of the cells the stone passes over.
Input
The first line contains the river width . is an integer between 1 and 1,000,000.
The second line contains the scores of the cells in order starting from cell 1, separated by spaces. Every score is an integer between -50,000 and 50,000.
Output
Print the that maximizes the sum of the scores and that maximum sum, separated by a space. If several values of reach the maximum, print the smallest one. If the maximum sum is 0 or less, running the plan is not worth it, so print 0 0.