#P16281. 「MierOI R1」Beyond

    ID: 17692 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>洛谷原创O2优化组合数学洛谷月赛双指针 two-pointer

「MierOI R1」Beyond

Problem Description

One day, Little M learned an algorithm called "fractional programming", which is used to solve the "fractional programming problem".

:::info[Fractional Programming Problem]{open}

There are nn items. The ii-th item has a value of aia_i and a weight of bib_i. Both aia_i and bib_i are positive integers.

Select kk items from the nn items, let the selected items be i1,i2,,iki_1,i_2,\dots,i_k, and maximize the value of

$$\frac{a_{i_1}+a_{i_2}+\dots+a_{i_k}}{b_{i_1}+b_{i_2}+\dots+b_{i_k}}$$

:::

Coincidentally, Little M had also solved a problem called sale. On a whim, he came up with a problem to test you.

Given n,kn,k, and the value sequence aa of the items, find the number of possible weight sequences bb of the items satisfying 1bi2\bm{1 \le b_i \le 2}, such that the following greedy strategy exactly finds the optimal solution to the "fractional programming problem":

  • Sort the items in descending order of their values ai\bm{a_i}. For items with the same value, sort them in ascending order of their indices i\bm{i}. Select the top kk items after sorting.

The answer should be modulo 998,244,353998,244,353.

Input Format

This problem contains multiple test cases.

The first line of the input contains a positive integer TT, indicating the number of test cases.

Then, the TT test cases follow sequentially. For each test case:

  • The first line contains two positive integers n,kn,k.
  • The second line contains nn positive integers a1,a2,,ana_1,a_2,\dots,a_n.

Output Format

For each test case, output a single line containing a non-negative integer, representing the number of weight sequences bb satisfying the condition. The answer should be modulo 998,244,353998,244,353.

2
2 1
10 9
6 3
10 10 8 6 6 5
3
15
5
16 1
256 225 196 169 144 121 100 81 64 49 36 25 16 9 4 1
16 2
256 225 196 169 144 121 100 81 64 49 36 25 16 9 4 1
16 15
256 225 196 169 144 121 100 81 64 49 36 25 16 9 4 1
16 14
256 225 196 169 144 121 100 81 64 49 36 25 16 9 4 1
16 9
256 225 196 169 144 121 100 81 64 49 36 25 16 9 4 1
34816
18176
32996
16887
3171

Hint

Explanation for Sample #1

For the first test case, the weight sequences bb satisfying the condition are (1,1),(1,2),(2,2)(1,1),(1,2),(2,2). When b=(2,1)b=(2,1), the greedy solution is a1b1=102=5\frac{a_1}{b_1}=\frac{10}{2}=5, and the optimal solution is a2b2=91=9\frac{a_2}{b_2}=\frac{9}{1}=9, so the greedy strategy fails to find the optimal solution.

Data Range

This problem uses bundled subtasks.

For all test cases, it is guaranteed that 1T51 \le T \le 5, 1kn20001 \le k \le n \le 2\,000, and 1ai1091 \le a_i \le 10^9.

::cute-table{tuack}

Subtask nn \le kk Score
11 55 n\le n 1010
22 1616 ^
33 4040 1515
44 200200
55 20002\,000 =1=1 55
66 ^ =2=2 1010
77 =n1=n-1 55
88 =n2=n-2 1010
99 n\le n 2020