Logo
(追記) (追記ここまで)

21639번 - Cooking 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB58181850.000%

문제

Stephen and Sergey are enrolled at the university and live on campus. So now they need to learn to cook.

The friends have learned to cook $n$ different dishes. After buying all the necessary food, the guys have decided that before they go shopping next time, they will cook the $i$-th dish exactly $a_i$ times.

Each day Sergey and Stephen choose two dishes $i$ and $j$ and cook them, cooking takes $c_{i, j}$ units of time. It's possible that $i=j,ドル that means that the $i$-th dish is cooked twice on that day.

The guys are quite lazy, so they want to minimize the total cooking time for all the days before the next shopping. Help them to do it!

입력

The first line contains a single integer $n$ (1ドル \le n \le 10$) --- the number of dishes that the guys can cook.

The second line contains $n$ positive integers $a_1, a_2, \ldots, a_n$ (1ドル \leq a_i \leq 50$) --- the number of times it must be cooked for each dish.

The next $n$ lines contain $n$ space separated integers $c_{i, j}$ (1ドル \le c_{i, j} \le 100$), the $j$-th number in the $i$-th line denotes cooking time of pair of dishes $i$ and $j$. It is guaranteed that $c_{i, j}=c_{j, i}$.

출력

Print one integer: the minimum total time of cooking, or $-1,ドル if it is impossible to make a cooking plan such that the $i$-th dish is cooked exactly $a_i$ times.

제한

예제 입력 1

3
2 2 2
1 4 3
4 4 5
3 5 6

예제 출력 1

10

예제 입력 2

2
2 39
23 9
9 23

예제 출력 2

-1

예제 입력 3

1
2
100

예제 출력 3

100

힌트

In the first test case it is optimal to cook the following pairs of dishes: $(1, 3),ドル $(1, 3),ドル $(2, 2)$.

출처

Olympiad > Russian Olympiad in Informatics > Russia Team High School Programming Contest > Russia Team High School Programming Contest 2020 G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /