9720: Tennis Match

内存限制:512 MB 时间限制:4 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

The training team has mmm candidate players, and now 2n2 n2n players need to be selected and paired to participate in nnn tennis doubles matches.

The iii-th player has an estimated capability eie_iei and is classified into junior and senior categories based on their training duration.

The iii-th match requires that the capability of any participating player does not exceed lil_ili, and for stability reasons, the coach requires that the capability difference between every two paired players does not exceed ddd.

Though there is no limitation for players to be paired based on the same category, in order to fully tap into the potential of junior players, the coach expects a few junior players to be selected for participation.

The coach tends to know, for each t=0,1,…,2nt = 0, 1, \ldots, 2 nt=0,1,,2n, if there exists a pairing scheme that contains exactly ttt junior players and also satisfies the above constraints. If no such scheme exists, output −1-11, or otherwise output the maximum possible sum of the ability values of the selected 2n2 n2n players.

输入格式

The first line contains an integer TTT (1<=T<=105), indicating the number of test cases.
Then follow TTT test cases. For each test case:
The first line contains three integers nnn, mmm and ddd .
The second line contains nnn integers l1,l2,…,lnl_1, l_2, \ldots, l_nl1,l2,,ln (1<=li<=109).
The next mmm lines describe the candidate players' information, the iii-th line of which contains two integers eie_iei and tit_iti (1<=ei<=109, ti∈{1,2}t_i \in \{1, 2\}ti{1,2}), indicating that the estimated capability of the iii-th player is eie_iei, and is junior type if ti=1t_i = 1ti=1, or otherwise senior type.
It is guaranteed that the sum of mmm across all TTT test cases does not exceed 2*105.

输出格式

For each test case, output (2n+1)(2 n + 1)(2n+1) integers in a line, where the iii-th integer represents the answer with respect to selecting exactly (i−1)(i - 1)(i1) junior players.

输入样例 复制

2
4 9 400
800 900 1050 1200
46 1
264 2
295 1
305 1
332 2
678 1
770 2
903 2
1291 2
4 9 400
800 900 1050 1200
46 1
264 2
295 1
305 2
332 2
678 2
770 2
903 2
1291 1

输出样例 复制

-1 -1 -1 -1 3593 -1 -1 -1 -1
-1 -1 3593 -1 -1 -1 -1 -1 -1