Purchasing Perishables

시간 제한1초메모리 제한2048 MB

요약
일별 식사 가격이 주어질 때, k일마다 장을 보고 그날 가격으로 k끼를 사서 N끼를 사는 총비용이 최소가 되는 k를 고른다.
난이도

보통10점 중 6점

유형
수학, 완전 탐색, 누적 합
정답자
아직 제출이 없습니다

문제

It's the beginning of a new semester at Mines, and Katie is planning out her grocery shopping for the foreseeable future. For each of the next NN days she needs ingredients for one meal. To inform her planning, she has compiled a list of prices the store is charging for a meal for each of the next NN days she wishes to plan out.

To keep her schedule orderly, Katie has decided to only go shopping on regular intervals. If there is a gap between shopping trips, she will buy exactly enough meals to last until her next purchase or until she has purchased all NN meals. For instance, if she is planning out 44 days and decides on an interval of 33 days, then she will purchase 33 meals on the first day, and 11 meal on the fourth day for a total of 44 meals.

Katie has a lot of work to do for her Data Structures class and doesn't have time to figure out an optimal interval between shopping trips to minimize her shopping budget. Given the prices for the next NN days, help Katie determine the optimal interval and the minimum budget she needs to allocate to purchasing meals for the next NN days, given she will only purchase food on regular intervals.

입력

The first line of input contains a single integer 1≤N≤1051 \leq N \leq 10^5, the number of days for which Katie has prices. The next line contains NN space-separated integers p_1,p_2,…,p_Np\_1, p\_2, \ldots, p\_N (1≤p_i≤1091 \leq p\_i \leq 10^9), where p_ip\_i is the price of a meal on the ithi^{\text{th}} day.

출력

The output should consist of a single integer, the minimum budget required to purchase NN meals for the next NN days.

예제3

  1. 예제 1

    입력
    4
    4 10 9 3
    
    예상 출력
    15
    
  2. 예제 2

    입력
    5
    15 89 19 54 30
    
    예상 출력
    75
    
  3. 예제 3

    입력
    3
    1000000000 1000000000 1000000000
    
    예상 출력
    3000000000