P1583 Magic Photos

Description

There are $n$ people (numbered $1 \sim n$) asking Jiajia for photos, but Jiajia can only give photos to $k$ of them. Jiajia assigns each person an initial weight $W_i$ based on how close they are. Then she sorts the initial weights in descending order, and each person gets a rank $D_i$ (also taking values $1 \sim n$). When determining $D_i$, if two people have the same $W_i$, the one with the smaller index comes first. According to the rank modulo $10$, these people are divided into $10$ categories. Specifically, define each person’s category index $C_i$ as $(D_i-1)\bmod 10 + 1$, so $C_i$ takes values $1 \sim 10$. People in category $i$ receive an extra weight $E_i$. Let the final weight be $F_i = W_i + E_{C_i}$. Your task is to find the $k$ people with the largest final weights and output their indices. In the final sorting, if two people have the same $F_i$, the one with the smaller index comes first.

Input Format

- The first line contains two integers separated by a space: $n$ and $k$. - The second line contains $10$ positive integers: $E_1 \sim E_{10}$. - The third line contains $n$ positive integers, where the $i$-th number is the weight $W_i$ of the person with index $i$.

Output Format

Output one line with $k$ integers separated by spaces: the indices of the people with the highest to lowest final weights $F_i$.

Explanation/Hint

Constraints: For $100\%$ of the testdata, $1 \leq n \leq 20000$, $1 \leq k \leq n$. All values are guaranteed to fit in the range of `int`. Translated by ChatGPT 5