#P15562. [CCPC 2025 哈尔滨站] 01 背包
[CCPC 2025 哈尔滨站] 01 背包
Problem Description
The 0/1 knapsack problem is a classic combinational optimization problem in algorithm competitions. Little w has learned a greedy algorithm to solve this problem. The definition of the 0/1 knapsack problem and Little w's greedy algorithm are as follows.
:
Given items. The weights of the items are positive integers , and the values of the items are positive integers . You are also given the knapsack capacity . You need to choose (, ), such that:
and maximize:
:
- Sort the items in descending order of . If is the same, sort by in descending order.
- Set an initial variable to , and enumerate from to . If , then set ; otherwise set .
- After the enumeration, you obtain the required and .
Of course, you know this algorithm is incorrect, but Little w does not believe it. Even if you give Little w some counterexamples, Little w still thinks that under many different , this algorithm can still produce the optimal . So now you want to construct a set of and such that:
- ( is a given constant), Little w's algorithm cannot obtain the optimal .
- Under condition , make as small as possible.
- Under conditions , make as small as possible.
- Under conditions , make as small as possible.
Now you need to construct a 0/1 knapsack instance that satisfies the requirements above to convince Little w. Can you do it? If there are multiple construction methods, you may output any one.
Input Format
The input consists of one line containing one integer (), representing the upper bound of .
Output Format
The first line contains one integer (), representing the number of items in the constructed 0/1 knapsack instance.
The second line outputs integers (), representing the item weights.
The third line outputs integers (), representing the item values.
It can be proven that under the given problem and input constraints, a solution within the given constraints always exists.
2
2
1 2
2 3
Hint
Translated by ChatGPT 5