PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000101. Shohag yêu thích ƯCLN (Shohag Loves GCD)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Shohag yêu thích ƯCLN (Shohag Loves GCD)
Shohag Loves GCD
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive integer and a strictly increasing set of distinct positive integers, construct the lexicographically largest array with every such that for every pair . If no such array exists, print -1.
Input
The first line contains . The second line contains the elements of in increasing order.
Output
Print -1 if impossible; otherwise print exactly elements of the lexicographically largest valid array.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
6 3
3 4 6
Output
6 4 4 3 4 3
Explanation
The lexicographically largest valid array is 6 4 4 3 4 3, using only elements from . For example, gives while . All other pairs are valid as well.