Hydra (Problem concept)
Difference between en1 and en2, changed 119 character(s)
Description↵
========↵

There is a Hydra, that you need to slay: it has **n** types of heads, numbered from 1 to n («lower» till «higher»). You can strike one head and cut it, but every head produces other heads. Your goal is to slay the hydra with minimum amount of strikes. Hydra is killed, when after cutting the last head, other won't appear.↵

Input↵
========↵
First string contains n — nuuber of head types (1 ≤ n ≤ 2000). The second string contains n elements: a_1 ... a_n (0 ≤ a_i ≤ 10^9) — starting quantity of every heads. Then comes n string, containing n nums (matrix b).↵

Output↵
========↵

Minimum amount of strikes to slay the Hydra. Write -1 if it is impossible↵

ПримерыExamples
-------↵

### 
ПримерExample 1↵
#### 
ВходInput:↵

- 3↵
- 1 0 0↵
- 0 1 2↵
- 0 0 0↵
- 0 0 0↵

Выход#### Output:↵

- 4↵

### 
ПримерExample 2↵
#### 
ВходInput:↵

- 5↵
- 1 1 1 1 1↵
- 0 1 0 0 0↵
- 0 0 1 0 0↵
- 0 0 0 1 0↵
- 0 0 0 0 1↵
- 0 0 0 0 0↵

#### 
ВыходOutput:↵

- 31↵

### 
ПримерExample 3:↵
#### 
ВходInput:↵

- 1↵
- 1↵
- 1↵

#### 
ВыходOutput:↵

- -1↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
ru6 Russian Im9223372036854775808 2025-12-04 11:37:05 38
en2 English Im9223372036854775808 2025-12-03 12:01:37 119
en1 English Im9223372036854775808 2025-12-03 11:45:17 1020 Initial revision for English translation
ru5 Russian Im9223372036854775808 2025-12-03 11:05:48 2 Мелкая правка: '- 1\n- 1\n#### Вых' -> '- 1\n- 1\n\n#### Вых'
ru4 Russian Im9223372036854775808 2025-12-03 11:05:29 12
ru3 Russian Im9223372036854775808 2025-12-03 11:04:58 44
ru2 Russian Im9223372036854775808 2025-12-02 22:51:10 10
ru1 Russian Im9223372036854775808 2025-12-02 18:57:19 1279 Первая редакция (опубликовано)