아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Azrael

시간 제한7초메모리 제한512 MB

요약
파이프로 숲에서 용기로 운반되는 주스의 총량을 최대로 한 뒤, c_i 곱하기 x_i의 제곱 합을 최소로 만드는 에너지를 출력한다.
난이도

보통10점 중 6점

유형
그리디, 수학, 정렬
정답자
아직 제출이 없습니다

문제

Gargamel is planning to clone his cat Azrael but for that he needs just one more ingredient: smurfberry juice.  Gargamel has a number of containers, each of which can hold one litre of juice.  Additionally there are some forests in which smurfberries grow (each forest has enough smurfberries to fill exactly one container with juice).  Gargamel has already captured Smurfs living in each of the forests, now he wants to use them to gather smurfberries for him.  Some forests are directly connected to some containers with pipes, which can be used to transport smurfberry juice.  Unfortunately, controlling Smurfs takes energy. Smurfs in some forests are easier to control than in others. The more smurfberries Smurfs collect from one forest the harder they are to control. After extensive research Gargamel concluded that in order for Smurfs in forest ii to gather x_ix\_i litres of smurfberry juice, he needs to use c_i⋅x_i2c\_i \cdot x\_i^2 energy. Gargamel, being both very greedy and very lazy wizard, wants to collect as much smurfberry juice as he can and then minimize total amount of energy he uses. All those constraints made him so confused that he needs your help now.

입력

First line of input contains two integers kk and pp (1≤k,p≤1001 \leq k, p \leq 100) denoting the number of forests and the number of juice containers respectively.  Second line contains kk integers c_1,c_2,…,c_kc\_1, c\_2, \ldots, c\_k (0≤c_i≤1000 \leq c\_i \leq 100) -- the energy consumption coefficients for controlling the Smurfs in each of the forests.  The next kk lines describe the pipes connecting forests and juice containers, each containing exactly p integers. The j-th integer in the i-th line is 11 if the forest ii is connected to the container jj, or 00 if there is no such connection.

출력

Output the minimum amount of energy Gargamel must use to collect as much smurfberry juice as possible. Your answer will be accepted if relative or absolute error is less than 10−510^{-5}.

예제4

  1. 예제 1

    입력
    2 1
    1 1
    1
    1
    
    예상 출력
    0.500000
    
  2. 예제 2

    입력
    2 1
    4 4
    1
    1
    
    예상 출력
    2.000000
    
  3. 예제 3

    입력
    3 2
    5 3 5
    1 0
    1 1
    0 1
    
    예상 출력
    5.454545
    
  4. 예제 4

    입력
    4 2
    1 1 1 1
    1 0
    1 0
    1 0
    0 1
    
    예상 출력
    1.333333