#P10987. [蓝桥杯 2023 国 Python A] 火车运输
[蓝桥杯 2023 国 Python A] 火车运输
Background
To account for the efficiency of the Python language, the time limit for this problem is relatively large. It is recommended to use PyPy3 to submit this problem.
Problem Description
A steel factory has a train used to transport scrap steel. It has two carriages: carriage 1 has a maximum load of , and carriage 2 has a maximum load of . There are pieces of scrap steel to be transported, and the weight of the -th piece is . To maximize transportation efficiency, the conductor wants to transport as much total weight as possible in a single trip. Please help the conductor compute the maximum total weight of scrap steel that can be carried in one trip.
Each piece of steel is independent and indivisible, and can only be placed into one of the carriages. When loading the steel, you only need to consider the weight constraints.
Input Format
The first line contains three integers , separated by a single space, representing the number of steel pieces and the maximum loads of the two carriages.
The second line contains integers, representing , with a single space between adjacent integers.
Output Format
Output one integer representing the answer.
3 10 8
8 9 1
18
Hint
For of the test cases, .
For all test cases, , and .
Sample Explanation
Carriage 1 loads the 2nd and 3rd pieces of steel, and carriage 2 loads the 1st piece of steel.
Translated by ChatGPT 5