PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000235. Đội thi bao phủ mọi chủ đề (Quiz Master)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đội thi bao phủ mọi chủ đề (Quiz Master)
Đội thi bao phủ mọi chủ đề (Quiz Master)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given student skill values and topics , student covers topic exactly when divides . Choose a nonempty group covering every topic, minimizing maximum skill minus minimum skill; print -1 if impossible.
Input
- First line: .
- Second line: integers .
Output
Print the minimum possible difference, or -1 if no team exists.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
2 4
3 7
Output
-1
Explanation
Neither student covers topic 2 or 4, so the answer is -1.
Example 2
Input
4 2
3 7 2 9
Output
0
Explanation
The student with skill 2 covers both topics on their own, so the minimum difference is zero.