PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000286. Cắt dây ruy băng (Cutting Ribbons)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cắt dây ruy băng (Cutting Ribbons)
Cutting Ribbons
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are ribbons of integer lengths . Each ribbon may remain intact or be cut into positive integer lengths. Joining pieces is forbidden. Select exactly pieces of equal length, discarding leftovers if desired. Find their maximum positive integer length, or if impossible.
Input
First line: . Second line: integers .
Output
Print the maximum value, or .
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input 1
3 4
7 5 9
Output 1
4
Explanation
Lengths 7, 5, 9 yield 1, 1, 2 pieces of length 4; length 5 yields only three pieces.
Input 2
2 11
2 5
Output 2
0
Explanation
The total is 7, so 11 positive groups are impossible.