CF119B.Before Exam

普及/提高-

通过率:0%

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 nn theorems. It is known that there will be kk 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 ii -th theorem by some number aia_{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.

输入格式

The first line contains two integers nn and kk ( 1<=k<=n<=1001<=k<=n<=100 ) — the number of theorems and the number of cards correspondingly. The second line contains nn integers aia_{i} ( 0<=ai<=1000<=a_{i}<=100 ), the ii -th number ( 1<=i<=n1<=i<=n ) corresponds to Vasya's proficiency in the ii -th theorem.

The third line contains number qq ( 0<=q<=1000<=q<=100 ) — the number of people that have taken the exam before Vasya. Each of the following qq lines contains the description of a student's card: integers from 11 to nn 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).

输出格式

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 10610^{-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 66 and 15.515.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 44 and 77 (his proficiency would equal 15.515.5 ) and in the worst case scenario he gets theorems 33 and 55 (his proficiency would equal 55 ).

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

首页