#P12149. 【MX-X11-T3】「蓬莱人形 Round 1」科学
【MX-X11-T3】「蓬莱人形 Round 1」科学
Description
Initially, you have A-type boxes, where the -th A-type box contains balls of color . Each A-type box has unlimited capacity. Additionally, there are B-type boxes available for purchase. The -th B-type box costs and has a maximum capacity of .
You can perform any number of operations, where each operation involves moving one ball from one box to another. However, the final state must satisfy:
- Every box contains balls of a single color.
- There exists a sequence of length (where can represent either an A-type or B-type box) such that for all , balls of color only appear in the -th A-type box or the box .
Your task is to purchase some B-type boxes (possibly none) and perform the operations to minimize the maximum number of balls in any box across all boxes. Under this condition, you must also minimize the total cost of purchased B-type boxes.
Unless explicitly specified, the term "box" refers to both A-type and B-type boxes collectively.
Input Format
The first line contains two integers and .
The second line contains positive integers .
The next lines each contain two positive integers and .
Output Format
Output two integers: the minimum possible maximum number of balls in any box, and the minimum total cost under this condition.
5 3
5 2 1 3 2
3 3
1 5
1 4
3 3
5 5
1 1 7 4 7
5 2
5 7
1 6
1 5
2 10
4 7
5 3
1 2 5 4 4
3 5
4 4
2 1
3 10
5 3
2 4 3 3 4
1 1
4 4
5 2
3 3
Hint
Explanation #1
Purchase the first B-type box . Move 2 color-1 balls from the first A-type box to this B-type box. The maximum number of balls in any box is , and the total cost is .
Explanation #2
Purchase the first B-type box and the fourth B-type box . Move 1 color-1 ball from the first A-type box to the fourth B-type box, 3 color-3 balls from the third A-type box to the first B-type box, and 3 color-5 balls from the fifth A-type box to the first B-type box. The maximum number of balls is , and the total cost is .
Constraints
This problem uses subtask scoring.
For all test data: , .
| Subtask | Special Property | Points | ||
|---|---|---|---|---|
| 1 | 6 | None | 10 | |
| 2 | 1 | 15 | ||
| 3 | 5 | 20 | ||
| 4 | All | 15 | ||
| 5 | None | 40 | ||
Translated by DeepSeek R1
京公网安备 11011102002149号