#P12149. 【MX-X11-T3】「蓬莱人形 Round 1」科学

    ID: 11679 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>二分O2优化优先队列梦熊比赛

【MX-X11-T3】「蓬莱人形 Round 1」科学

Description

Initially, you have nn A-type boxes, where the ii-th A-type box contains aia_i balls of color ii. Each A-type box has unlimited capacity. Additionally, there are mm B-type boxes available for purchase. The ii-th B-type box costs wiw_i and has a maximum capacity of bib_i.

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:

  1. Every box contains balls of a single color.
  2. There exists a sequence pp of length nn (where pip_i can represent either an A-type or B-type box) such that for all i[1,n]i \in [1, n], balls of color ii only appear in the ii-th A-type box or the box pip_i.

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 nn and mm.

The second line contains nn positive integers a1,a2,,ana_1, a_2, \ldots, a_n.

The next mm lines each contain two positive integers bib_i and wiw_i.

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 (3,3)(3, 3). 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 33, and the total cost is 33.

Explanation #2

Purchase the first B-type box (5,2)(5, 2) and the fourth B-type box (1,5)(1, 5). 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 44, and the total cost is 77.

Constraints

This problem uses subtask scoring.

For all test data: 1n,m2×1051 \le n, m \le 2 \times 10^5, 1ai,bi,wi1091 \le a_i, b_i, w_i \le 10^9.

Subtask nn \le mm \le Special Property Points
1 6 None 10
2 2×1052 \times 10^5 1 15
3 5 20
4 2×1052 \times 10^5 All ai,bi2a_i, b_i \le 2 15
5 None 40

Translated by DeepSeek R1