CF119B.Before Exam

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya is about to take his first university exam in about several minutes. And it's not just some ordinary exam, it's on mathematical analysis. Of course, right now Vasya can only think of one thing: what the result of his talk with the examiner will be...

To prepare for the exam, one has to study proofs of n theorems. It is known that there will be k examination cards on the exam and each card contains distinct theorems. Besides, no theorem is mentioned in more than one card (that is, theorems won't be mentioned in any card). During the exam several students may get the same card.

We do not know the exact way theorems are distributed by cards, however the students that took the exam before Vasya told him what theorems their cards contained. Vasya evaluates his level of proficiency in the i-th theorem by some number a__i. The level of proficiency in some card is the average of the levels of proficiency in the theorems that are included in the card. Now Vasya wants to know the minimally and maximally possible levels of his proficiency in the card he gets on the exam. Vasya wants to determine it by the data he has collected from other students. Unfortunately, Vasya has no time left to do the math and he asked you to help him.

瓦西娅几分钟后就要参加他的第一场大学考试了。而且这可不是一场普通的考试,而是一场数学分析考试。当然,此时此刻瓦西娅满脑子只想着一件事:他与考官的问答环节结果会如何……

为准备这场考试,考生需学习 nn 个定理的证明。已知考试中将有 kk 张考题卡片,每张卡片包含 个互不相同的定理。此外,任一定理至多出现在一张卡片中(即共有 个定理不会出现在任何卡片中)。考试过程中,若干名考生可能抽到同一张卡片。

我们并不知道这些定理在卡片上的具体分配方式,但此前参加过考试的学生已将各自所抽卡片中包含的定理告诉了瓦西娅。瓦西娅用某个数值 aia_i 来评估自己对第 ii 个定理的掌握程度。某张卡片的掌握程度定义为该卡片所含各定理掌握程度的平均值。现在瓦西娅希望根据他从其他学生处收集到的数据,推断出他在考试中抽到的卡片所对应的掌握程度的最小可能值与最大可能值。不幸的是,瓦西娅已没有时间自行完成计算,因此请求你帮助他。

输入格式

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 100) — the number of theorems and the number of cards correspondingly. The second line contains n integers a__i (0 ≤ a__i ≤ 100), the i-th number (1 ≤ i ≤ n) corresponds to Vasya's proficiency in the i-th theorem.

The third line contains number q (0 ≤ q ≤ 100) — the number of people that have taken the exam before Vasya. Each of the following q lines contains the description of a student's card: integers from 1 to n inclusive. They are the numbers of theorems included in the card in the order in which they are enumerated in the input data. The numbers are given in an arbitrary order. It is guaranteed that the given cards are valid (that is, that all theorems in one card are different and that different people get cards that either don't contain the same theorems or coincide up to the theorems' permutation).

第一行包含两个整数 nn 和 kk(1≤k≤n≤1001 \leq k \leq n \leq 100)——分别表示定理的总数和卡片的张数。
第二行包含 nn 个整数 aia_i(0≤ai≤1000 \leq a_i \leq 100),其中第 ii 个数(1≤i≤n1 \leq i \leq n)表示瓦西娅对第 ii 个定理的掌握程度。

第三行包含一个整数 qq(0≤q≤1000 \leq q \leq 100)——表示在瓦西娅之前参加考试的学生人数。接下来的 qq 行,每行描述一名学生的卡片: 个取值范围为 11 到 nn(含端点)的整数。这些整数表示该卡片所包含的定理编号,其顺序与输入中定理的编号顺序一致。这些整数以任意顺序给出。保证所给卡片均合法(即:同一张卡片中所有定理编号互不相同;且不同学生所持卡片,要么不包含相同的定理,要么仅在定理排列顺序上存在差异)。

输出格式

Print two real numbers, representing Vasya's minimum and maximum proficiency in the card he will get on the exam. The absolute or relative error should not exceed 10 - 6.

输出两个实数,分别表示瓦西娅在考试中将抽到的卡片上其熟练度的最小值和最大值。绝对或相对误差不得超过 10−610^{-6}。

输入输出样例

  • 输入#1

    7 3
    7 15 0 19 10 5 12
    2
    1 6
    7 4

    输出#1

    5.0000000000 15.5000000000
  • 输入#2

    4 2
    10 8 1 17
    2
    2 3
    3 2

    输出#2

    4.5000000000 13.5000000000

说明/提示

Let's analyze the first sample. Vasya's proficiency in the cards whose content he already knows equals 6 and 15.5 correspondingly. The three theorems that are left are only enough to make one exam card. If we consider all possible variants of theorems included in the card we can see that in the best case scenario Vasya gets the card that contains theorems 4 and 7 (his proficiency would equal 15.5) and in the worst case scenario he gets theorems 3 and 5 (his proficiency would equal 5).

The ⌊ x⌋ operation denotes taking integer part of real number x (rounding down).

我们来分析第一个样例。瓦西娅对内容已知的卡片的熟练度分别为 6 和 15.5。剩余的三个定理仅够制作一张考试卡片。若考虑该卡片可能包含的所有定理组合,则可知:在最优情况下,瓦西娅抽到包含定理 4 和定理 7 的卡片(其熟练度为 15.5);而在最差情况下,他抽到包含定理 3 和定理 5 的卡片(其熟练度为 5)。

符号 ⌊ x⌋ 表示取实数 x 的整数部分(即向下取整)。

输入解题思路,AI测评打分。不知道怎么写?

首页