luogu#P4852. yyf hates choukapai

    ID: 3804 远端评测题 912ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2018单调队列洛谷原创Special Judge凸完全单调性(wqs 二分)前缀和队列

yyf hates choukapai

Background

Unlucky yyf can never draw the cards he wants, so he also really hates drawing cards. But when playing sif, it is impossible to avoid drawing cards, so he went to consult the lucky dew. dew told him the secret of drawing cards, but yyf still did not know how to make his luck as high as possible, so he came to you.

Problem Description

dew tells yyf that when a person draws each card, the luck value is fixed. The luck value of the ii-th card is aia_i. When doing a consecutive draw, the luck value equals the luck value of the first card in that consecutive draw.

“The sum of luck for each draw operation” means: the sum of luck from every single draw plus the sum of luck from every consecutive draw. For one consecutive draw, its luck is not weighted; it is counted only once.

yyf wants to do cc-card consecutive draws (draw cc consecutive cards) for nn times, and single draws for mm times. Because doing single draws all the time is too tiring, yyf does not want to do more than dd consecutive single draws (doing exactly dd consecutive single draws is allowed). There are c×n+mc \times n + m cards in total. The drawing order cannot be changed. Each card must be drawn exactly once. You may only change which cards are drawn as consecutive draws and which are drawn as single draws. Then, what is the maximum possible sum of luck for all draw operations, and how can it be achieved?

Input Format

Line 11 contains 44 positive integers n,m,c,dn, m, c, d.

Line 22 contains c×n+mc \times n + m positive integers, where the ii-th integer aia_i represents the luck value of the ii-th card.

Output Format

Line 11 outputs one positive integer representing the maximum possible sum of luck for yyf’s draw operations.

Line 22 outputs nn positive integers representing the indices of the first card of each consecutive draw. If there are multiple valid solutions, output any one. (If you cannot output a solution, please still output any nn integers on the second line, otherwise you may get 00 points.)

Output the indices in increasing order.

3 3 3 3
2 7 1 4 5 3 6 8 5 1 2 9
36
2 5 9
2 5 2 2
7 3 3 7 7 5 1 10 2
41
2 6 

Hint

For 20%20\% of the testdata, 1n51 \le n \le 5, 1m51 \le m \le 5, 2c52 \le c \le 5.

For 50%50\% of the testdata, 1n401 \le n \le 40, 1m2001 \le m \le 200, 2c202 \le c \le 20.

Another 20%20\% of the testdata has d=md = m.

For 100%100\% of the testdata, 1n401 \le n \le 40, 1m800001 \le m \le 80000, 2c30002 \le c \le 3000, 1ai100001 \le a_i \le 10000, 1dm1 \le d \le m, d×(n+1)md \times (n + 1) \ge m.

There are 1010 test points in total. For each test point: if the answer is wrong, you get 00 points; if the answer is correct but the plan is wrong, you get 66 points; if both the answer and the plan are correct, you get 1010 points.

Sample explanation: the output plan is exactly the sample explanation QAQ.

Sample 1: single draw 11, consecutive draw 242 \sim 4, consecutive draw 575 \sim 7, single draw 88, consecutive draw 9119 \sim 11, single draw 1212. The total luck sum is 2+7+5+8+5+9=362 + 7 + 5 + 8 + 5 + 9 = 36.

Sample 2: single draw 11, consecutive draw 232 \sim 3, single draw 44, single draw 55, consecutive draw 676 \sim 7, single draw 88, single draw 99. The total luck sum is 7+3+7+7+5+10+2=417 + 3 + 7 + 7 + 5 + 10 + 2 = 41.

It can be proven that, under the constraints, the above two plans achieve the maximum possible total luck sum.

Translated by ChatGPT 5