cswork / OAOpen practice workspace

NetflixOA #2

Rank Movies by Similarity Score (FrontEnd :)

Estimated EasyJudge-ready

Topics (AI-labelled)Stacks & HeapsIn-place Arrays

The similarity of each movie to the target movie is known. The score of a movie group is the sum of the k highest similarities in the group. Return the scores in the input order of the groups, without reordering the groups.

Input

The first line contains N G k; the second line contains N similarities; then G lines follow, each giving the group size m followed by m 0-based movie indices. This site uses N≤100000 and G≤10000, both ≥1; 1≤k≤m≤N, the indices within each group are distinct and valid, and the total number of members over all groups is ≤200000. Scores are in [0,1] with at most 6 decimal places, given as plain decimal input.

Output

First output G, then output the G group scores, which may be on separate lines. Each value may have an absolute or relative error of 1e-5; equivalent integers, decimals, and scientific notation are accepted, and no fixed number of decimal places is required.

Example 1

Input:

5 2 2
0.300000 0.200000 0.100000 0.400000 0.500000
3 1 2 4
3 0 3 4

Output:

2
0.700000 0.900000

Example 2

Input:

3 2 1
1.000000 0.000000 0.500000
3 0 1 2
2 1 2

Output:

2
1.000000 0.500000

Example 3

Input:

3 2 3
0.000001 0.000002 0.999999
3 0 1 2
3 2 1 0

Output:

2
1.000002 1.000002

Example notes

Example 1: the top two values of the two groups are 0.5+0.2=0.7 and 0.5+0.4=0.9, keeping the group order. Example 2: k=1, and the maxima of the two groups are 1 and 0.5. Example 3: k equals the group size, so both groups add all three values to get 1.000002; the order within a group does not affect the score.

Editorial

Loading solution…