#p1465. Jury Compromise
Jury Compromise
题目描述
In Bulgaria, a far-away country, the verdicts in court trials are determined by a jury consisting of members of the general public. Every time a trial is set to begin, a jury has to be selected, which is done as follows. First, several people are drawn randomly from the public. For each person in this pool, defence and prosecution assign a grade from 0 to 20 indicating their preference for this person. 0 means total dislike, 20 on the other hand means that this person is considered ideally suited for the jury. Based on the grades of the two parties, the judge selects the jury. In order to ensure a fair trial, the tendencies of the jury to favour either defence or prosecution should be as balanced as possible. The jury therefore has to be chosen in a way that is satisfactory to both parties. We will now make this more precise: given a pool of n potential jurors and two values di (the defence's value) and pi (the prosecution's value) for each potential juror i, you are to select a jury of m persons. If J is a subset of {1,..., n} with m elements, then D(J ) = sum(dk) k belong to J and P(J) = sum(pk) k belong to J are the total values of this jury for defence and prosecution. For an optimal jury J , the value |D(J) - P(J)| must be minimal. If there are several jurys with minimal |D(J) - P(J)|, one which maximizes D(J) + P(J) should be selected since the jury should be as ideal as possible for both parties. You are to write a program that implements this jury selection process and chooses an optimal jury given a set of candidates.
在遥远的国家保加利亚,嫌犯是否有罪,须由陪审团决定。陪审团是由法官从公众中挑选的。
先随机挑选n 个人作为陪审团的候选人,然后再从这n 个人中选m 人组成陪审团。
选m 人的办法是:控方和辩方会根据对候选人的喜欢程度,给所有候选人打分,分值从0 到20。为了公平起见,法官选出陪审团的原则是:选出的m 个人,必须满足辩方总分D和控方总分P的差的绝对值**|D-P|**最小。
如果有多种选择方案的**|D-P|** 值相同,那么选辩控双方总分之和D+P最大的方案即可。
输入格式
输入数据包含几个测试用例。
每组包含两个整数n,m。n是候选人的数量,m是陪审团成员的数量 。
这些值将满足1 <= n <= 200,1 <= m <= 20,当然m <= n。以下n行包含i = 1,...,n的两个整数pi和di。
两组中间分隔一个空白行。 文件以0 0结束。
输出格式
请严格按照样例格式输出,包括第三行行首的空格。
样例数据
input
4 2
1 2
2 3
4 1
6 2
0 0
output
Jury #1
Best jury has value 6 for prosecution and value 4 for defence:
2 3
数据和spj来源
fanchenyang_2021