#P15258. [USACO26JAN2] Declining Invitations S
[USACO26JAN2] Declining Invitations S
Description
contestants participated in a contest, each placing a distinct rank from to . There are criteria used to invite contestants to participate in the final round, and the th-ranked contestant satisfies a specified of them ().
The invitation process runs as follows. First, the top students who satisfy the st criteria will be invited. Then, out of all students who haven't yet been invited, the top (or all remaining if there are fewer than remaining) students who satisfy the nd criterion will be invited. This process repeats, for each from to ().
However, some contestants will decline to participate in the final round, in which case they will be ignored when determining who to invite.
You are given a permutation of . For each from to , determine the sum of the ranks of the contestants who will be invited if the participants with ranks given by the first elements of decline to attend.
Input Format
The first line contains and ().
The next line contains .
The next line contains .
The next lines each contain (), followed by distinct integers in , representing the criteria that the th-ranked contestant satisfies. It is guaranteed that .
Output Format
Output lines, the sum of ranks of invitees before each declination.
5 1
3
5 1 3 2 4
1 1
1 1
1 1
1 1
1 1
6
6
9
6
4
5 4
1 1 1 1
1 2 3 4 5
1 1
2 1 2
2 2 3
2 3 4
1 4
10
14
12
9
5
6 10
5 6 4 1 3 3 3 6 5 3
1 4 6 5 2 3
1 9
5 4 3 9 5 10
10 6 2 10 1 7 8 3 9 4 5
10 4 5 3 1 2 9 10 6 7 8
2 3 1
8 1 9 7 4 3 10 6 2
21
20
16
10
5
3
Hint
Sample 1 Explanation
There is only one criterion. The top three remaining contestants who have not declined will be invited.
Sample 2 Explanation
Initially, the th contestant gets invited under criterion for all .
After the first declination, the th contestant gets invited under criterion for all .
SCORING:
- Inputs 4-6:
- Inputs 7-8:
- Inputs 9-10:
- Inputs 11-16: No additional constraints.
京公网安备 11011102002149号