PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000102. Dãy con dài nhất với BCNN bị chặn (Longest Subsequence)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dãy con dài nhất với BCNN bị chặn (Longest Subsequence)
Longest Subsequence
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of positive integers and a limit , choose a longest subsequence whose LCM does not exceed . The subsequence must preserve the original order. The LCM of an empty subsequence is defined as . Any maximum-length valid subsequence is accepted.
Input
The first line contains . The second line contains elements .
Output
The first line prints the actual LCM and the optimal length . The second line prints exactly strictly increasing selected indices. For , the second line is empty.
Subtasks
- Subtask 1 (20 points): , , .
- Subtask 2 (30 points): , , .
- Subtask 3 (50 points): , .
Examples
Input
7 8
6 2 9 2 7 2 3
Output
6 5
1 2 4 6 7
Explanation
Selecting positions yields , whose LCM is . Its length is , the maximum achievable.