cswork / OA打开练习工作台

WayfairOA #3

Smash The Bricks(NG)

估计中等可在线判题

考点(AI 标注)贪心调度原地数组

n bricks are indexed from 1 to n, and the distinct positive integers strength[i] give the hit strength each brick must take. The big hammer breaks any brick in one hit and can be used at most k times; each hit of the small hammer reduces the required strength by 1, so breaking a brick with the small hammer alone takes strength[i] hits. Find the minimum total number of hits to break all bricks, and give the indices of the bricks broken by each hammer. Each brick belongs to the group of exactly one hammer. Return any optimal grouping; a brick with strength 1 may use either hammer, as long as the quota is respected and the total number of hits is optimal.

输入格式

The first line contains n and k. The second line contains n distinct integers strength[i]. 1≤n≤200000, 0≤k≤200000, 1≤strength[i]≤1000000000. k may be greater than n. The original problem's ranges and distinctness guarantee are kept in full.

输出格式

Output exactly three lines. The first line is the minimum total number of hits, which may exceed 32 bits. The second line is the 1-based indices of the big-hammer group, strictly increasing; if the big hammer is not used, output -1. The third line is the 1-based indices of the small-hammer group, strictly increasing; if the small hammer is not used, output -1. The two groups must be disjoint and cover all bricks, and the big-hammer group has size at most k. Do not output brackets or group sizes. This is a line-by-line serialization of the original 2D return array.

样例 1

输入:

1 0
2

输出:

2
-1
1

样例 2

输入:

7 4
3 2 5 4 6 7 9

输出:

13
3 5 6 7
1 2 4

样例 3

输入:

8 9
7 9 3 2 5 8 4 6

输出:

8
1 2 3 4 5 6 7 8
-1

样例 4

输入:

3 0
10000000 100000000 1000000000

输出:

1110000000
-1
1 2 3

样例说明

All four public examples come from the original problem. Example 1 has no big-hammer quota and takes 2 hits. Example 2 uses the big hammer on bricks 3, 5, 6, 7, and the rest cost 3+2+4=9 with the small hammer, for 13 hits in total. Example 3 has a quota of 9, more than the 8 bricks, so all can use the big hammer, for 8 hits in total. Example 4 has no big hammer, for a total of 1110000000 hits.