PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000149. Chọn tập tránh tổng mục tiêu (Anti-knapsack)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chọn tập tránh tổng mục tiêu (Anti-knapsack)
Anti-knapsack
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers , choose as many distinct integers from through as possible so that no subset of the chosen integers sums to . The empty subset has sum .
Print the largest possible number of chosen integers together with any set achieving that size.
Input
The input contains two integers .
Output
Print the maximum cardinality , then distinct integers in . No subset of those integers may have sum .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
5 3
Output
3
2 4 5
Explanation
For , the set has three elements. No subset sums to : is too small by itself, and every other selected number exceeds . Adding would create the forbidden sum .