PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000035. Máu cuối cùng của quái vật (Monsters Battle Royale)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Máu cuối cùng của quái vật (Monsters Battle Royale)
Monsters Battle Royale
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are monsters with initial positive health values . In each move, one living monster attacks another; the target loses health equal to the attacker's current health. Monsters with nonpositive health disappear. Find the minimum attainable health of the final survivor.
Input
The first line contains ; the second contains .
Output
Print the minimum attainable final health.
Subtasks
- Subtask 1 (20 points): ;
- Subtask 2 (30 points): ;
- Subtask 3 (50 points): ;
Examples
Input
4
2 10 8 40
Output
2
Explanation
The GCD of is , and health changes preserve multiples of this value. A survivor with health is attainable.