Throughput P87774


Statement
 

pdf   zip

Elon Musk is optimizing an assembly line in one of his factories and he needs your help to find an assignment of humanoid robots to stations that maximizes throughput (number of work units processed per hour).

0.60 There are a total of rr identical humanoid robots to be distributed among nn workstations (numbered 1 to nn) of the assembly line. At each station ii, robots collect work units from the output storage of station i1i-1, perform some station-specific operation (such as welding, painting...), and then place the processed work units on the output storage of station ii, to be collected by robots from station i+1i+1. Each robot at station ii can process pip_i work units per hour. Assume that robots at station 1 collect work units from a warehouse with unlimited supply, and that the output of station nn can be consumed at an arbitrarily high rate.

0.40

Can you find the maximum throughput that can be achieved by distributing the rr robots among the nn stations optimally?

Input

Each case starts with rr and nn. Follow the nn integers p1,,pnp_1, \dots, p_n, all between 1 and 10910^9. You can assume 1n1051 \le n \le 10^5 and nr109n \le r \le 10^9.

Output

For every case, print the maximum possible throughput of the assembly line.

Public test cases
  • Input

    4 2  10 10
    3 3  4 1 12
    17 2  42 69
    1000000000 4  500000000 42 1000000000 23
    

    Output

    20
    1
    420
    14861537791
    
  • Information
    Author
    Felix Miravé
    Language
    English
    Official solutions
    C++
    User solutions
    C++