#P13009. 【MX-X13-T4】「KDOI-12」好胜是人的本能,功利是社会的本性。

    ID: 11697 远端评测题 2000ms 512MiB 尝试: 1 已通过: 1 难度: 6 上传者: 标签>动态规划 DP贪心O2优化整除分块梦熊比赛

【MX-X13-T4】「KDOI-12」好胜是人的本能,功利是社会的本性。

Description

Given a sequence of positive integers a1,,ana_1, \ldots, a_n of length nn and a positive integer mm satisfying mmaxaim \geq \max a_i, you can perform any number of operations (including zero) on the sequence. In each operation, you may select an interval [l,r][l, r] and for all lirl \leq i \leq r, set aimaia_i \gets \left\lfloor \frac{m}{a_i} \right\rfloor.

Your task is to determine:

  1. The maximum possible value of j=1naj\sum_{j=1}^n a_j achievable through these operations.
  2. The minimum number of operations required to achieve this maximum sum.

Input Format

This problem contains multiple test cases.

  • The first line contains a positive integer TT, the number of test cases.
  • For each test case:
    • The first line contains two positive integers nn and mm.
    • The second line contains nn positive integers a1,,ana_1, \ldots, a_n.

Output Format

For each test case, output two non-negative integers:

  1. The maximum possible sum j=1naj\sum_{j=1}^n a_j.
  2. The minimum number of operations required to achieve this sum.
3
2 5
1 2
5 10
1 5 2 4 3
10 10
1 4 2 5 1 6 2 7 1 10
7 1
28 3
80 5

Hint

Sample Explanation

For the second test case in the sample input, selecting the following 3 intervals achieves the maximum sum of 2828:

  1. [1,2][1, 2]
  2. [2,5][2, 5]
  3. [4,5][4, 5]

It can be proven that this is one of the optimal solutions.

Data Range

This problem uses bundled testing.

Subtask Points nn \leq n\sum n \leq Special Properties
11 99 44 400400 None
22 2727 10310^3 10410^4
33 1111 10510^5 10610^6 A
44 1616 B
55 3737 None
  • Special Property A: aima_i \leq \sqrt{m}.
  • Special Property B: aia_i divides mm (i.e., aima_i \mid m).

For all test cases:

  • 1T1051 \leq T \leq 10^5,
  • 1n1051 \leq n \leq 10^5,
  • 1n1061 \leq \sum n \leq 10^6,
  • 1aim10121 \leq a_i \leq m \leq 10^{12}.

Translated by DeepSeek V3.