import java.util.*;
import java.lang.*;
public class B119
	{
	public static void main(String[] args)
		{
		Scanner in =new Scanner(System.in);
		int n = in.nextInt();int k = in.nextInt();int counter1=0,check=0;
		int i=0,j=0;Data a[] = new Data[n];int m = n/k;double min=10000000.00,max=-1.00,avg=0.0;int sum=0;
		for(i=0;i<n;i++)
			{
			a[i]=new Data(in.nextInt(),i);
			}
		int q = in.nextInt();
		int b[][] = new int[q][m];int count[] = new int[n];
		for(i=0;i<q;i++)
			{check=0;
			sum=0;
			for(j=0;j<m;j++)
				{
				b[i][j] = in.nextInt();count[b[i][j]-1]++;
				sum+=a[b[i][j]-1].getValue();
				}
			for(int l=0;l<i;l++)
				{
				if(Arrays.equals(b[i],b[l]))
					{
					check=1;break;
					}
				}
			if(check==0)
				{
				counter1++;
				}
			avg = sum/(double)m;
			if(avg<min)
				{
				min=avg;//System.out.println("min"+min);
				}
			if(avg>max)
				{
				max=avg;//System.out.println("max"+max);
				}
			}int counter=0;
		Data[] obj = new Data[n];
		for(i=0;i<n;i++)
			{
			if(count[i]==0)
				{
				obj[counter] = new Data(a[i].getValue(),a[i].getIndex());counter++;
				}
			}
		if(counter==0||counter<m||counter1>=k)
			{
			System.out.printf(min+" "+max);
			System.exit(0);
			}
		obj = MergeSort(obj,0,counter-1);sum=0;
		for(i=0;i<m;i++)
			{
			sum+=obj[i].getValue();
			}
		avg = sum/(double)m;sum=0;
		if(avg<min)
			{
			min=avg;
			}
		for(i=counter-1;i>=counter-m;i--)
			{
			sum+=obj[i].getValue();
			}
		avg = sum/(double)m;
		if(avg>max)
			{
			max=avg;
			}
		System.out.printf(min+" "+max);
		System.exit(0);
		}
	public static Data[] MergeSort(Data[] a,int low,int high)
		{
		if(low>=high)
			{
			return a;
			}
		else
			{
			int middle=(high+low)/2;
			Data[] left = new Data [middle-low+1];
			Data[] right = new Data [high-middle];
			int i=0,count=0;
			for(i=0;i<=middle-low;i++)
				{
				left[count]=a[i];count++;
				}
			count=0;
			for(i=middle+1-low;i<=high-low;i++)
				{
				right[count]=a[i];count++;
				}
			Data[] SortedLeft =MergeSort(left,low,middle);
			Data[] SortedRight =MergeSort(right,middle+1,high);
			return Merge(SortedLeft,SortedRight,low,high);
			}
		}
	public static Data[] Merge(Data[] sl,Data[] sr,int low,int high)
		{
		Data fina[]  = new Data[high-low+1];
		int i=0,middle =(high+low)/2;
		int a=0,b=0,alimit=middle-low+1,blimit=high-middle;
		int n=alimit+blimit;
		/*System.out.println("sl");
		for(i=0;i<alimit;i++)
			{
			int x = sl[i].getValue();
			int y = sl[i].getIndex();
			System.out.println(x+" "+y);
			}
		System.out.println("sr");
		for(i=0;i<blimit;i++)
			{
			int x = sr[i].getValue();
			int y = sr[i].getIndex();
			System.out.println(x+" "+y);
			}*/
		for(i=0;i<n;i++)
			{
			if(a!=alimit&&(b==blimit||(sl[a].getValue()<=sr[b].getValue()&&a<alimit)))
				{
				fina[i]=new Data(sl[a].getValue(),sl[a].getIndex());
				a++;
				}
			else
				{
				fina[i]=new Data(sr[b].getValue(),sr[b].getIndex());
				b++;
				}
			}
		return fina;
		}
	}
 class Data
	{
	private int val;
	private int index;
	public Data(int x,int y)
		{
		val=x;
		index=y;
		}
	public int getValue()
		{
		return this.val;
		}
	public int getIndex()
		{
		return this.index;
		}
	}


import java.util.*;
import java.lang.*;
public class B119
	{
	public static void main(String[] args)
		{
		Scanner in =new Scanner(System.in);
		int n = in.nextInt();int k = in.nextInt();
		int i=0,j=0;Data a[] = new Data[n];int m = n/k;double min=10000000.00,max=-1.00,avg=0.0;int sum=0;
		for(i=0;i<n;i++)
			{
			a[i]=new Data(in.nextInt(),i);
			}
		int q = in.nextInt();
		int b[][] = new int[q][m];int count[] = new int[n];
		for(i=0;i<q;i++)
			{sum=0;
			for(j=0;j<m;j++)
				{
				b[i][j] = in.nextInt();count[b[i][j]-1]++;
				sum+=a[b[i][j]-1].getValue();
				}
				avg = sum/(double)m;
				//System.out.println("avg"+avg);
			if(avg<min)
				{
				min=avg;//System.out.println("min"+min);
				}
			if(avg>max)
				{
				max=avg;//System.out.println("max"+max);
				}
			}int counter=0;
		Data[] obj = new Data[n];
		for(i=0;i<n;i++)
			{
			if(count[i]==0)
				{
				obj[counter] = new Data(a[i].getValue(),a[i].getIndex());counter++;
				}
			}
		if(counter==0||counter<m)
			{
			System.out.printf(min+" "+max);
			System.exit(0);
			}
		obj = MergeSort(obj,0,counter-1);sum=0;
		for(i=0;i<m;i++)
			{
			sum+=obj[i].getValue();
			}
		avg = sum/(double)m;sum=0;
		if(avg<min)
			{
			min=avg;
			}
		for(i=counter-1;i>=counter-m;i--)
			{
			sum+=obj[i].getValue();
			}
		avg = sum/(double)m;
		if(avg>max)
			{
			max=avg;
			}
		System.out.printf(min+" "+max);
		System.exit(0);
		}
	public static Data[] MergeSort(Data[] a,int low,int high)
		{
		if(low>=high)
			{
			return a;
			}
		else
			{
			int middle=(high+low)/2;
			Data[] left = new Data [middle-low+1];
			Data[] right = new Data [high-middle];
			int i=0,count=0;
			for(i=0;i<=middle-low;i++)
				{
				left[count]=a[i];count++;
				}
			count=0;
			for(i=middle+1-low;i<=high-low;i++)
				{
				right[count]=a[i];count++;
				}
			Data[] SortedLeft =MergeSort(left,low,middle);
			Data[] SortedRight =MergeSort(right,middle+1,high);
			return Merge(SortedLeft,SortedRight,low,high);
			}
		}
	public static Data[] Merge(Data[] sl,Data[] sr,int low,int high)
		{
		Data fina[]  = new Data[high-low+1];
		int i=0,middle =(high+low)/2;
		int a=0,b=0,alimit=middle-low+1,blimit=high-middle;
		int n=alimit+blimit;
		/*System.out.println("sl");
		for(i=0;i<alimit;i++)
			{
			int x = sl[i].getValue();
			int y = sl[i].getIndex();
			System.out.println(x+" "+y);
			}
		System.out.println("sr");
		for(i=0;i<blimit;i++)
			{
			int x = sr[i].getValue();
			int y = sr[i].getIndex();
			System.out.println(x+" "+y);
			}*/
		for(i=0;i<n;i++)
			{
			if(a!=alimit&&(b==blimit||(sl[a].getValue()<=sr[b].getValue()&&a<alimit)))
				{
				fina[i]=new Data(sl[a].getValue(),sl[a].getIndex());
				a++;
				}
			else
				{
				fina[i]=new Data(sr[b].getValue(),sr[b].getIndex());
				b++;
				}
			}
		return fina;
		}
	}
 class Data
	{
	private int val;
	private int index;
	public Data(int x,int y)
		{
		val=x;
		index=y;
		}
	public int getValue()
		{
		return this.val;
		}
	public int getIndex()
		{
		return this.index;
		}
	}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Locale;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputStreamReader in = new InputStreamReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputStreamReader inSt, PrintWriter out) {
        InputReader in = new InputReader(inSt);

        int n = in.nextInt();
        int k = in.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int q = in.nextInt();
        int min = (int) 1e5;
        int max = -1;

        int qNum = n / k;
        for (int i = 0; i < q; i++) {
            int sum = 0;
            boolean isOk = true;
            for (int j = 0; j < qNum; j++) {
                int index = in.nextInt() - 1;
                if (a[index] < 0) {
                    isOk = false;
                }
                sum += a[index];
                a[index] = -1;
            }
            if (isOk) {
                min = Math.min(min, sum);
                max = Math.max(max, sum);
            }
        }

        Arrays.sort(a);
        int firstPos = 0;
        while (a[firstPos] < 0) {
            firstPos++;
        }

        int passedB = firstPos / qNum;
        if (passedB < k) {
            int sum = 0;
            for (int i = firstPos; i < firstPos + qNum; i++) {
                sum += a[i];
            }
            min = Math.min(min, sum);

            sum = 0;
            for (int i = n - 1; i > n - qNum - 1; i--) {
                sum += a[i];
            }
            max = Math.max(max, sum);
        }

        out.print(String.format(Locale.US, "%.10f %.10f", min / (qNum + 0.), max / (qNum + 0.)));

    }

    class InputReader {
        public BufferedReader reader;
        private String[] currentArray;
        int curPointer;

        public InputReader(InputStreamReader inputStreamReader) {
            reader = new BufferedReader(inputStreamReader);
        }

        public String next() {
            try {
                currentArray = null;
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public void nextChars(char[] t) {
            try {
                currentArray = null;
                reader.read(t);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public char nextChar() {
            try {
                currentArray = null;
                return (char) reader.read();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public int nextInt() {
            if ((currentArray == null) || (curPointer >= currentArray.length)) {
                try {
                    currentArray = reader.readLine().split(" ");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                curPointer = 0;
            }
            return Integer.parseInt(currentArray[curPointer++]);
        }

        public long nextLong() {
            if ((currentArray == null) || (curPointer >= currentArray.length)) {
                try {
                    currentArray = reader.readLine().split(" ");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                curPointer = 0;
            }
            return Long.parseLong(currentArray[curPointer++]);
        }

    }
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Locale;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputStreamReader in = new InputStreamReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputStreamReader inSt, PrintWriter out) {
        InputReader in = new InputReader(inSt);

        int n = in.nextInt();
        int k = in.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int q = in.nextInt();
        int min = (int) 1e5;
        int max = -1;

        int qNum = n / k;
        for (int i = 0; i < q; i++) {
            int sum = 0;
            boolean isOk = true;
            for (int j = 0; j < qNum; j++) {
                int index = in.nextInt() - 1;
                if (a[index] < 0) {
                    isOk = false;
                }
                sum += a[index];
                a[index] = -1;
            }
            if (isOk) {
                min = Math.min(min, sum);
                max = Math.max(max, sum);
            }
        }

        Arrays.sort(a);
        int firstPos = 0;
        while (firstPos < n && a[firstPos] < 0) {
            firstPos++;
        }

        int passedB = firstPos / qNum;
        if (passedB < k) {
            int sum = 0;
            for (int i = firstPos; i < firstPos + qNum; i++) {
                sum += a[i];
            }
            min = Math.min(min, sum);

            sum = 0;
            for (int i = n - 1; i > n - qNum - 1; i--) {
                sum += a[i];
            }
            max = Math.max(max, sum);
        }

        out.print(String.format(Locale.US, "%.10f %.10f", min / (qNum + 0.), max / (qNum + 0.)));

    }

    class InputReader {
        public BufferedReader reader;
        private String[] currentArray;
        int curPointer;

        public InputReader(InputStreamReader inputStreamReader) {
            reader = new BufferedReader(inputStreamReader);
        }

        public String next() {
            try {
                currentArray = null;
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public void nextChars(char[] t) {
            try {
                currentArray = null;
                reader.read(t);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public char nextChar() {
            try {
                currentArray = null;
                return (char) reader.read();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public int nextInt() {
            if ((currentArray == null) || (curPointer >= currentArray.length)) {
                try {
                    currentArray = reader.readLine().split(" ");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                curPointer = 0;
            }
            return Integer.parseInt(currentArray[curPointer++]);
        }

        public long nextLong() {
            if ((currentArray == null) || (curPointer >= currentArray.length)) {
                try {
                    currentArray = reader.readLine().split(" ");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                curPointer = 0;
            }
            return Long.parseLong(currentArray[curPointer++]);
        }

    }
}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.InputMismatchException;

public class Main
{
	public void foo()
	{
		MyScanner scan = new MyScanner();
		int n = scan.nextInt();
		int k = scan.nextInt();
		int p = n / k;
		int[] a = new int[n];
		for(int i = 0;i < n;++i)
		{
			a[i] = scan.nextInt();
		}
		double minLevel = Double.MAX_VALUE;
		double maxLevel = Double.MIN_VALUE;
		int q = scan.nextInt();
		boolean[] vis = new boolean[n];
		while(q-- > 0)
		{
			int sum = 0;
			for(int i = 0;i < p;++i)
			{
				int x = scan.nextInt() - 1;
				sum += a[x];
				vis[x] = true;
			}
			minLevel = Math.min(minLevel, (double)sum / p);
			maxLevel = Math.max(maxLevel, (double)sum / p);
		}
		ArrayList<Integer> arr = new ArrayList<Integer>();
		for(int i = 0;i < n;++i)
		{
			if(!vis[i])
			{
				arr.add(a[i]);
			}
		}
		if(arr.size() < p || p * k == n - arr.size())
		{
			System.out.println(minLevel);
			System.out.println(maxLevel);
		}
		else
		{
			Collections.sort(arr);
			int sum = 0;
			for(int i = 0;i < p;++i)
			{
				sum += arr.get(i);
			}
			System.out.println(Math.min((double)sum / p, minLevel));
			sum = 0;
			for(int i = arr.size() - 1;i >= arr.size() - p;--i)
			{
				sum += arr.get(i);
			}
			System.out.println(Math.max((double)sum / p, maxLevel));
		}
	}

	public static void main(String[] args)
	{
		new Main().foo();
	}

	class MyScanner
	{
	    private byte[] buf = new byte[1024];
	    private int curChar;
	    private int numChars;
	    BufferedInputStream bis = new BufferedInputStream(System.in);

	    public int read()
	    {
	        if (-1 == numChars)
	        {
	        	throw new InputMismatchException();
	        }
	        if (curChar >= numChars)
	        {
	            curChar = 0;
	            try
	            {
	                numChars = bis.read(buf);
	            }
	            catch (IOException e)
	            {
	                throw new InputMismatchException();
	            }
	            if (numChars <= 0)
	            {
	            	return -1;
	            }
	        }
	        return buf[curChar++];
	    }

	    public int nextInt()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        int sgn = 1;
	        if (c == '-')
	        {
	            sgn = -1;
	            c = read();
	        }
	        int res = 0;
	        do
	        {
	            if (c < '0' || c > '9')
	            {
	            	throw new InputMismatchException();
	            }
	            res *= 10;
	            res += c - '0';
	            c = read();
	        } while (!isSpaceChar(c));
	        return res * sgn;
	    }

	    public String next()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        StringBuilder res = new StringBuilder();
	        do
	        {
	            res.appendCodePoint(c);
	            c = read();
	        } while (!isSpaceChar(c));
	        return res.toString();
	    }

	    private boolean isSpaceChar(int c)
	    {
	        return ' ' == c || '\n' == c || '\r' == c || '\t' == c || -1 == c;
	    }
	}
}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.InputMismatchException;

public class Main
{
	public void foo()
	{
		MyScanner scan = new MyScanner();
		int n = scan.nextInt();
		int k = scan.nextInt();
		int p = n / k;
		int[] a = new int[n];
		for(int i = 0;i < n;++i)
		{
			a[i] = scan.nextInt();
		}
		double minLevel = Double.MAX_VALUE;
		double maxLevel = Double.MIN_VALUE;
		int q = scan.nextInt();
		boolean[] vis = new boolean[n];
		while(q-- > 0)
		{
			int sum = 0;
			for(int i = 0;i < p;++i)
			{
				int x = scan.nextInt() - 1;
				sum += a[x];
				vis[x] = true;
			}
			minLevel = Math.min(minLevel, (double)sum / p);
			maxLevel = Math.max(maxLevel, (double)sum / p);
		}
		ArrayList<Integer> arr = new ArrayList<Integer>();
		for(int i = 0;i < n;++i)
		{
			if(!vis[i])
			{
				arr.add(a[i]);
			}
		}
		if(arr.size() < p)
		{
			System.out.println(minLevel);
			System.out.println(maxLevel);
		}
		else
		{
			Collections.sort(arr);
			int sum = 0;
			for(int i = 0;i < p;++i)
			{
				sum += arr.get(i);
			}
			System.out.println(Math.min((double)sum / p, minLevel));
			sum = 0;
			for(int i = arr.size() - 1;i >= arr.size() - p;--i)
			{
				sum += arr.get(i);
			}
			System.out.println(Math.max((double)sum / p, maxLevel));
		}
	}

	public static void main(String[] args)
	{
		new Main().foo();
	}

	class MyScanner
	{
	    private byte[] buf = new byte[1024];
	    private int curChar;
	    private int numChars;
	    BufferedInputStream bis = new BufferedInputStream(System.in);

	    public int read()
	    {
	        if (-1 == numChars)
	        {
	        	throw new InputMismatchException();
	        }
	        if (curChar >= numChars)
	        {
	            curChar = 0;
	            try
	            {
	                numChars = bis.read(buf);
	            }
	            catch (IOException e)
	            {
	                throw new InputMismatchException();
	            }
	            if (numChars <= 0)
	            {
	            	return -1;
	            }
	        }
	        return buf[curChar++];
	    }

	    public int nextInt()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        int sgn = 1;
	        if (c == '-')
	        {
	            sgn = -1;
	            c = read();
	        }
	        int res = 0;
	        do
	        {
	            if (c < '0' || c > '9')
	            {
	            	throw new InputMismatchException();
	            }
	            res *= 10;
	            res += c - '0';
	            c = read();
	        } while (!isSpaceChar(c));
	        return res * sgn;
	    }

	    public String next()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        StringBuilder res = new StringBuilder();
	        do
	        {
	            res.appendCodePoint(c);
	            c = read();
	        } while (!isSpaceChar(c));
	        return res.toString();
	    }

	    private boolean isSpaceChar(int c)
	    {
	        return ' ' == c || '\n' == c || '\r' == c || '\t' == c || -1 == c;
	    }
	}
}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.InputMismatchException;

public class Main
{
	public void foo()
	{
		MyScanner scan = new MyScanner();
		int n = scan.nextInt();
		int k = scan.nextInt();
		int p = n / k;
		int[] a = new int[n];
		for(int i = 0;i < n;++i)
		{
			a[i] = scan.nextInt();
		}
		double minLevel = Double.MAX_VALUE;
		double maxLevel = Double.MIN_VALUE;
		int q = scan.nextInt();
		boolean[] vis = new boolean[n];
		while(q-- > 0)
		{
			int sum = 0;
			for(int i = 0;i < p;++i)
			{
				int x = scan.nextInt() - 1;
				sum += a[x];
				vis[x] = true;
			}
			minLevel = Math.min(minLevel, (double)sum / p);
			maxLevel = Math.max(maxLevel, (double)sum / p);
		}
		ArrayList<Integer> arr = new ArrayList<Integer>();
		for(int i = 0;i < n;++i)
		{
			if(!vis[i])
			{
				arr.add(a[i]);
			}
		}
		Collections.sort(arr);
		int sum = 0;
		for(int i = 0;i < p;++i)
		{
			sum += arr.get(i);
		}
		System.out.println(Math.min((double)sum / p, minLevel));
		sum = 0;
		for(int i = arr.size() - 1;i >= arr.size() - p;--i)
		{
			sum += arr.get(i);
		}
		System.out.println(Math.max((double)sum / p, maxLevel));
	}

	public static void main(String[] args)
	{
		new Main().foo();
	}

	class MyScanner
	{
	    private byte[] buf = new byte[1024];
	    private int curChar;
	    private int numChars;
	    BufferedInputStream bis = new BufferedInputStream(System.in);

	    public int read()
	    {
	        if (-1 == numChars)
	        {
	        	throw new InputMismatchException();
	        }
	        if (curChar >= numChars)
	        {
	            curChar = 0;
	            try
	            {
	                numChars = bis.read(buf);
	            }
	            catch (IOException e)
	            {
	                throw new InputMismatchException();
	            }
	            if (numChars <= 0)
	            {
	            	return -1;
	            }
	        }
	        return buf[curChar++];
	    }

	    public int nextInt()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        int sgn = 1;
	        if (c == '-')
	        {
	            sgn = -1;
	            c = read();
	        }
	        int res = 0;
	        do
	        {
	            if (c < '0' || c > '9')
	            {
	            	throw new InputMismatchException();
	            }
	            res *= 10;
	            res += c - '0';
	            c = read();
	        } while (!isSpaceChar(c));
	        return res * sgn;
	    }

	    public String next()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        StringBuilder res = new StringBuilder();
	        do
	        {
	            res.appendCodePoint(c);
	            c = read();
	        } while (!isSpaceChar(c));
	        return res.toString();
	    }

	    private boolean isSpaceChar(int c)
	    {
	        return ' ' == c || '\n' == c || '\r' == c || '\t' == c || -1 == c;
	    }
	}
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int n,k,x;
    double maxi = 0,mini=100,sum;
    cin >> n >> k;
    const int c= n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second = 0;
    }
    int q;
    cin >> q;
    for(int i = 0 ;i < q;i++){
        sum=0;
        for(int j =0;j<c;j++){
            cin >> x;
            sum+=(double)prof[x-1].first/c;
            prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini)mini=sum;
    }
    sort(prof,prof+n);
    int cnt=0;
    sum=0;
    bool ok=0;
    for(int i = 0; i < n;i++){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c){break;ok=1}
    }
    if(sum < mini&&ok) mini = sum;
    ok=0;
    sum=0;
    cnt=0;
    for(int i = n-1; i >=0 ;i--){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c){break;ok=1;}
    }
    if(sum > maxi&&ok) maxi = sum;
    cout << fixed << setprecision(6) << mini << ' ' << maxi;

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int n,k,x;
    double maxi = 0,mini=100,sum;
    cin >> n >> k;
    const int c= n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second = 0;
    }
    int q;
    cin >> q;
    for(int i = 0 ;i < q;i++){
        sum=0;
        for(int j =0;j<c;j++){
            cin >> x;
            sum+=(double)prof[x-1].first/c;
            prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini)mini=sum;
    }
    sort(prof,prof+n);
    int cnt=0;
    sum=0;
    for(int i = 0; i < n;i++){
        if(!prof[i].second){
            sum+=prof[i].first/c;
            cnt++;
        }
        if(cnt == c)break;
    }
    if(sum < mini) mini = sum;
    sum=0;
    cnt=0;
    for(int i = n-1; i >=0 ;i--){
        if(!prof[i].second){
            sum+=prof[i].first/c;
            cnt++;
        }
        if(cnt == c)break;
    }
    if(sum > maxi) maxi = sum;
    cout << fixed << setprecision(6) << mini << ' ' << maxi;

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int n,k,x;
    double mini = 1000,maxi=0,sum;
    cin >> n >> k;
    const int questionCntPerPaper = n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second=0;
    }
    int q;
    cin >> q;
    bool shoftAlwra2a;
    int tempq = q;
    for(int i = 0; i < tempq; i++){
        shoftAlwra2a=0;sum=0;
        for(int j =0;j < questionCntPerPaper;j++){
            cin >> x;
            if(prof[x-1].second&&!shoftAlwra2a){q--;shoftAlwra2a=1;}
            else if(prof[x-1].second&&shoftAlwra2a);
            else sum+=(double)prof[x-1].first/questionCntPerPaper;
            prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini && sum)mini=sum;
    }
    if(q==k)cout << fixed << setprecision(6) << mini << ' ' << maxi;
    else{
        sort(prof,prof+n);
        sum=0;x=0;
        for(int i = 0; i < n; i++){
            if(!prof[i].second){sum+=(double)prof[i].first/questionCntPerPaper;x++;}
            if(x == k)break;
        }
        if(sum < mini)mini=sum;
        sum=0;x=0;
        for(int i = n-1; i >= 0; i--){
            if(!prof[i].second){sum+=(double)prof[i].first/questionCntPerPaper;x++;}
            if(x == k)break;
        }
        if(sum > maxi)maxi=sum;
        cout << fixed << setprecision(6) << mini << ' ' << maxi;
    }

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int cnt=0;
    bool ok=0;
    int n,k,x;
    double maxi = 0,mini=100,sum;
    cin >> n >> k;
    const int c= n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second = 0;
    }
    int q;
    cin >> q;
    int mashy;
    for(int i = 0 ;i < q;i++){
        sum=0;mashy=0;
        for(int j =0;j<c;j++){
            cin >> x;
            sum+=(double)prof[x-1].first/c;
            if(prof[x-1].second)mashy++;
            else prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini)mini=sum;
    }
    if(k==q-mashy)goto hell;
    sort(prof,prof+n);
    sum=0;
    for(int i = 0; i < n;i++){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c){ok=1;break;}
    }
    if(sum < mini&&ok) mini = sum;
    ok=0;
    sum=0;
    cnt=0;
    for(int i = n-1; i >=0 ;i--){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c){ok=1;break;}
    }
    if(sum > maxi&&ok) maxi = sum;
    hell:;
    cout << fixed << setprecision(6) << mini << ' ' << maxi;

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int n,k,x;
    double mini = 1000,maxi=0,sum;
    cin >> n >> k;
    const int questionCntPerPaper = n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second=0;
    }
    int q;
    cin >> q;
    bool shoftAlwra2a;
    int tempq = q;
    for(int i = 0; i < tempq; i++){
        shoftAlwra2a=0;sum=0;
        for(int j =0;j < questionCntPerPaper;j++){
            cin >> x;
            if(prof[x-1].second&&!shoftAlwra2a){q--;shoftAlwra2a=1;}
            else if(prof[x-1].second&&shoftAlwra2a);
            else sum+=(double)prof[x-1].first/questionCntPerPaper;
            prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini && sum)mini=sum;
    }
    if(q==k)cout << fixed << setprecision(6) << mini << ' ' << maxi;
    else{
        sort(prof,prof+n);
        sum=0;x=0;
        for(int i = 0; i < n; i++){
            if(!prof[i].second){sum+=(double)prof[i].first/questionCntPerPaper;x++;}
            if(x == questionCntPerPaper)break;
        }
        if(sum < mini)mini=sum;
        sum=0;x=0;
        for(int i = n-1; i >= 0; i--){
            if(!prof[i].second){sum+=(double)prof[i].first/questionCntPerPaper;x++;}
            if(x == questionCntPerPaper)break;
        }
        if(sum > maxi)maxi=sum;
        cout << fixed << setprecision(6) << mini << ' ' << maxi;
    }

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int n,k,x;
    double mini = 10000,maxi=0,sum;
    cin >> n >> k;
    const int questionCntPerPaper = n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second=0;
    }
    int q;
    cin >> q;
    bool shoftAlwra2a;
    int tempq = q;
    for(int i = 0; i < tempq; i++){
        shoftAlwra2a=0;sum=0;
        for(int j =0;j < questionCntPerPaper;j++){
            cin >> x;
            if(prof[x-1].second&&!shoftAlwra2a){q--;shoftAlwra2a=1;}
            else if(prof[x-1].second&&shoftAlwra2a);
            else sum+=(double)prof[x-1].first/questionCntPerPaper;
            prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini && !shoftAlwra2a)mini=sum;
    }
    if(q==k)cout << fixed << setprecision(6) << mini << ' ' << maxi;
    else{
        sort(prof,prof+n);
        sum=0;x=0;
        for(int i = 0; i < n; i++){
            if(!prof[i].second){sum+=(double)prof[i].first/questionCntPerPaper;x++;}
            if(x == questionCntPerPaper)break;
        }
        if(sum < mini)mini=sum;
        sum=0;x=0;
        for(int i = n-1; i >= 0; i--){
            if(!prof[i].second){sum+=(double)prof[i].first/questionCntPerPaper;x++;}
            if(x == questionCntPerPaper)break;
        }
        if(sum > maxi)maxi=sum;
        cout << fixed << setprecision(6) << mini << ' ' << maxi;
    }

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int cnt=0;
    bool ok=0;
    int n,k,x;
    double maxi = 0,mini=100,sum;
    cin >> n >> k;
    const int c= n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second = 0;
    }
    int q;
    cin >> q;
    int mashy=0;
    for(int i = 0 ;i < q;i++){
        sum=0;
        for(int j =0;j<c;j++){
            cin >> x;
            if(prof[x-1].second)mashy++;
            else {
                sum+=(double)prof[x-1].first/c;
                prof[x-1].second=1;
            }
        }
        if(sum > maxi && sum)maxi=sum;
        if(sum < mini && sum)mini=sum;
    }
    if(k==q-mashy)goto hell;
    sort(prof,prof+n);
    sum=0;
    for(int i = 0; i < n;i++){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c){ok=1;break;}
    }
    if(sum < mini&&ok) mini = sum;
    ok=0;
    sum=0;
    cnt=0;
    for(int i = n-1; i >=0 ;i--){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c){ok=1;break;}
    }
    if(sum > maxi&&ok) maxi = sum;
    hell:;
    cout << fixed << setprecision(6) << mini << ' ' << maxi;

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);*/

    int n,k;
    long double mini=100,maxi=0;
    cin >> n >> k;
    int prof[n];
    bool stillOk[n];
    for(int i = 0;i < n; i++){
        cin >> prof[i];
        stillOk[i]=1;
    }
    int q,question,sum;
    cin >> q;
    int temp = n/k;
    for(int i = 0;i < q; i++){
        sum=0;
        for(int j = 0; j< temp;j++){
            cin >> question;
            stillOk[question-1]=0;
            sum+=prof[question-1];
        }
        if((long double)sum/temp > maxi)maxi=(long double)sum/temp;
        if((long double)sum/temp < mini)mini=(long double)sum/temp;
    }
    vector <int> stillOkQuestion;
    for(int i = 0; i<n; i++){
        if(stillOk[i]){
            stillOkQuestion.push_back(prof[i]);
        }
    }
    sort(stillOkQuestion.begin(),stillOkQuestion.end());
    sum=0;
    for(int i = 0; i < temp; i++){
        sum+=stillOkQuestion[i];
    }
    if((long double)sum/2<mini)mini=(long double)sum/2;
    temp = stillOkQuestion.size();
    sum=0;
    reverse(stillOkQuestion.begin(),stillOkQuestion.end());
    for(int i = 0; i < temp; i++){
        sum+=stillOkQuestion[i];
    }
    if((long double)sum/2>maxi)maxi=(long double)sum/2;
    cout << fixed << mini << ' ' << maxi << endl;

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int n,k,x;
    double mini = 10000,maxi=0,sum;
    cin >> n >> k;
    const int questionCntPerPaper = n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second=0;
    }
    int q;
    cin >> q;
    bool shoftAlwra2a;
    int tempq = q;
    for(int i = 0; i < tempq; i++){
        shoftAlwra2a=0;sum=0;
        for(int j =0;j < questionCntPerPaper;j++){
            cin >> x;
            if(prof[x-1].second&&!shoftAlwra2a){q--;shoftAlwra2a=1;}
            else if(prof[x-1].second&&shoftAlwra2a);
            else sum+=(double)prof[x-1].first/questionCntPerPaper;
            prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini && sum)mini=sum;
    }
    if(q==k)cout << fixed << setprecision(6) << mini << ' ' << maxi;
    else{
        sort(prof,prof+n);
        sum=0;x=0;
        for(int i = 0; i < n; i++){
            if(!prof[i].second){sum+=(double)prof[i].first/questionCntPerPaper;x++;}
            if(x == questionCntPerPaper)break;
        }
        if(sum < mini)mini=sum;
        sum=0;x=0;
        for(int i = n-1; i >= 0; i--){
            if(!prof[i].second){sum+=(double)prof[i].first/questionCntPerPaper;x++;}
            if(x == questionCntPerPaper)break;
        }
        if(sum > maxi)maxi=sum;
        cout << fixed << setprecision(6) << mini << ' ' << maxi;
    }

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int n,k,x;
    double mini = 1000,maxi=0,sum;
    cin >> n >> k;
    const int questionCntPerPaper = n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second=0;
    }
    int q;
    cin >> q;
    bool shoftAlwra2a;
    for(int i = 0; i < q; i++){
        shoftAlwra2a=0;sum=0;
        for(int j =0;j < questionCntPerPaper;j++){
            cin >> x;
            if(prof[x-1].second&&!shoftAlwra2a){q--;shoftAlwra2a=1;}
            else if(prof[x-1].second&&shoftAlwra2a);
            else sum+=(double)prof[x-1].first/questionCntPerPaper;
            prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini && sum)mini=sum;
    }
    if(q==k)cout << fixed << setprecision(6) << mini << ' ' << maxi;
    else{
        sort(prof,prof+n);
        sum=0;x=0;
        for(int i = 0; i < n; i++){
            if(!prof[i].second){sum+=(double)prof[i].first/questionCntPerPaper;x++;}
            if(x == questionCntPerPaper)break;
        }
        if(sum < mini)mini=sum;
        sum=0;x=0;
        for(int i = n-1; i >= 0; i--){
            if(!prof[i].second){sum+=(double)prof[i].first/questionCntPerPaper;x++;}
            if(x == questionCntPerPaper)break;
        }
        if(sum > maxi)maxi=sum;
        cout << fixed << setprecision(6) << mini << ' ' << maxi;
    }

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);*/

    int n,k;
    long double mini=100,maxi=0;
    cin >> n >> k;
    int prof[n];
    bool stillOk[n];
    for(int i = 0;i < n; i++){
        cin >> prof[i];
        stillOk[i]=1;
    }
    int q,question,sum;
    cin >> q;
    int temp = n/k;
    for(int i = 0;i < q; i++){
        sum=0;
        for(int j = 0; j< temp;j++){
            cin >> question;
            stillOk[question-1]=0;
            sum+=prof[question-1];
        }
        if((long double)sum/temp > maxi)maxi=(long double)sum/temp;
        if((long double)sum/temp < mini)mini=(long double)sum/temp;
    }
    vector <int> stillOkQuestion;
    for(int i = 0; i<n; i++){
        if(stillOk[i]){
            stillOkQuestion.push_back(prof[i]);
        }
    }
    sort(stillOkQuestion.begin(),stillOkQuestion.end());
    sum=0;
    for(int i = 0; i < temp; i++){
        sum+=stillOkQuestion[i];
    }
    if((long double)sum/2<mini)mini=(long double)sum/2;
    temp = stillOkQuestion.size();
    sum=0;
    reverse(stillOkQuestion.begin(),stillOkQuestion.end());
    for(int i = 0; i < temp; i++){
        sum+=stillOkQuestion[i];
    }
    if((long double)sum/2>maxi)maxi=(long double)sum/2;
    cout << fixed << setprecision(7) << mini << ' ' << maxi << endl;

    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);*/

    int n,k;
    long double mini=100,maxi=0;
    cin >> n >> k;
    int prof[n];
    bool stillOk[n];
    for(int i = 0;i < n; i++){
        cin >> prof[i];
        stillOk[i]=1;
    }
    int q,question,sum;
    cin >> q;
    int temp = n/k;
    for(int i = 0;i < q; i++){
        sum=0;
        for(int j = 0; j< temp;j++){
            cin >> question;
            stillOk[question-1]=0;
            sum+=prof[question-1];
        }
        if((long double)sum/temp > maxi)maxi=(long double)sum/temp;
        if((long double)sum/temp < mini)mini=(long double)sum/temp;
    }
    vector <int> stillOkQuestion;
    for(int i = 0; i<n; i++){
        if(stillOk[i]){
            stillOkQuestion.push_back(prof[i]);
        }
    }
    sort(stillOkQuestion.begin(),stillOkQuestion.end());
    sum=0;
    for(int i = 0; i < temp; i++){
        sum+=stillOkQuestion[i];
    }
    if((long double)sum/2<mini)mini=(long double)sum/2;
    temp = stillOkQuestion.size();
    sum=0;
    reverse(stillOkQuestion.begin(),stillOkQuestion.end());
    for(int i = 0; i < temp; i++){
        sum+=stillOkQuestion[i];
    }
    if((long double)sum/2>maxi)maxi=(long double)sum/2;
    cout << fixed << setprecision(6) << mini << ' ' << maxi << endl;

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int cnt=0;
    bool ok=0;
    int n,k,x;
    double maxi = 0,mini=100,sum;
    cin >> n >> k;
    const int c= n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second = 0;
    }
    int q;
    cin >> q;
    for(int i = 0 ;i < q;i++){
        sum=0;
        for(int j =0;j<c;j++){
            cin >> x;
            sum+=(double)prof[x-1].first/c;
            prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini)mini=sum;
    }
    if(k==q)goto hell;
    sort(prof,prof+n);
    sum=0;
    for(int i = 0; i < n;i++){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c){ok=1;break;}
    }
    if(sum < mini&&ok) mini = sum;
    ok=0;
    sum=0;
    cnt=0;
    for(int i = n-1; i >=0 ;i--){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c){ok=1;break;}
    }
    if(sum > maxi&&ok) maxi = sum;
    hell:;
    cout << fixed << setprecision(6) << mini << ' ' << maxi;

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int n,k,x;
    double maxi = 0,mini=100,sum;
    cin >> n >> k;
    const int c= n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second = 0;
    }
    int q;
    cin >> q;
    for(int i = 0 ;i < q;i++){
        sum=0;
        for(int j =0;j<c;j++){
            cin >> x;
            sum+=(double)prof[x-1].first/c;
            prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini)mini=sum;
    }
    sort(prof,prof+n);
    int cnt=0;
    sum=0;
    bool ok=0;
    for(int i = 0; i < n;i++){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c){ok=1;break;}
    }
    if(sum < mini&&ok) mini = sum;
    ok=0;
    sum=0;
    cnt=0;
    for(int i = n-1; i >=0 ;i--){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c){ok=1;break;}
    }
    if(sum > maxi&&ok) maxi = sum;
    cout << fixed << setprecision(6) << mini << ' ' << maxi;

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);*/

    int n,k;
    long double mini=100,maxi=0;
    cin >> n >> k;
    long double prof[n];
    bool stillOk[n];
    for(int i = 0;i < n; i++){
        cin >> prof[i];
        stillOk[i]=1;
    }
    int q,question,sum;
    cin >> q;
    int temp = n/k;
    for(int i = 0;i < q; i++){
        sum=0;
        for(int j = 0; j< temp;j++){
            cin >> question;
            stillOk[question-1]=0;
            sum+=prof[question-1];
        }
        if((long double)sum/temp > maxi)maxi=(long double)sum/temp;
        if((long double)sum/temp < mini)mini=(long double)sum/temp;
    }
    vector <int> stillOkQuestion;
    for(int i = 0; i<n; i++){
        if(stillOk[i]){
            stillOkQuestion.push_back(prof[i]);
        }
    }
    sort(stillOkQuestion.begin(),stillOkQuestion.end());
    sum=0;
    for(int i = 0; i < temp; i++){
        sum+=stillOkQuestion[i];
    }
    if((long double)sum/2<mini)mini=(long double)sum/2;
    temp = stillOkQuestion.size();
    sum=0;
    reverse(stillOkQuestion.begin(),stillOkQuestion.end());
    for(int i = 0; i < temp; i++){
        sum+=stillOkQuestion[i];
    }
    if((long double)sum/2>maxi)maxi=(long double)sum/2;
    cout << fixed << setprecision(7) << mini << ' ' << maxi << endl;

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main() {

    int n,k,x;
    double maxi = 0,mini=100,sum;
    cin >> n >> k;
    const int c= n/k;
    pair <int,bool> prof[n];
    for(int i = 0; i < n; i++){
        cin >> prof[i].first;
        prof[i].second = 0;
    }
    int q;
    cin >> q;
    for(int i = 0 ;i < q;i++){
        sum=0;
        for(int j =0;j<c;j++){
            cin >> x;
            sum+=(double)prof[x-1].first/c;
            prof[x-1].second=1;
        }
        if(sum > maxi)maxi=sum;
        if(sum < mini)mini=sum;
    }
    sort(prof,prof+n);
    int cnt=0;
    sum=0;
    for(int i = 0; i < n;i++){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c)break;
    }
    if(sum < mini) mini = sum;
    sum=0;
    cnt=0;
    for(int i = n-1; i >=0 ;i--){
        if(!prof[i].second){
            sum+=(double)prof[i].first/c;
            cnt++;
        }
        if(cnt == c)break;
    }
    if(sum > maxi) maxi = sum;
    cout << fixed << setprecision(6) << mini << ' ' << maxi;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define li long long
#define ld long double
#define x first
#define y second
#define pt pair<int, int>
#define pll pair<ll, ll>
#define forn(i, t) for(int i = 0; i < (t); i++)
#define fore(i, f, t) for(int i = (f); i < (t); i++)
#define forr(i, f, t) for(int i = (f) - 1; i >= (t); i--)
#define all(x) (x).begin(), (x).end()
#define ins insert

using namespace std;

const int INF = 2147483647;
const int MOD = 1000000007;
const li INF64 = 9223372036854775807;
const ld EPS = 1e-7;

mt19937 myrand(time(NULL));

const int N = 113;

int n, m, k, p, cnt;
int a[N];
set<int> used;
double tc[N];

bool read(){
	if(scanf("%d%d", &n, &k) != 2)
		return 0;
	m = n / k;
	used = set<int>();
	forn(i, n){
		scanf("%d", &a[i]);
		used.insert(i);
	}
	scanf("%d", &p);
	int t, sum;
	cnt = 0;
	forn(i, p){
		sum = 0;
		forn(j, m){
			scanf("%d", &t);
			--t;
			if (used.find(t) != used.end() && j == 0)
				cnt++;
			used.erase(t);
			sum += a[t];
		}
		tc[i] = (1.0 * sum / m);
	}
	return 1;
}

void solve(){
	double minn = 1.0 * N * N * N, maxn = 0.0;

	forn(i, p){
		minn = min(minn, tc[i]);
		maxn = max(maxn, tc[i]);
	}

	vector<int> cur;

	for (auto it : used)
		cur.pb(a[it]);

	sort(all(cur));
	if (sz(cur) < m || cnt == k){
		printf("%.15f %.15f\n", minn, maxn);
		return;
	}

	int sum = 0;
	forn(i, m)
		sum += cur[i];
	minn = min(minn, 1.0 * sum / m);

	sum = 0;
	forr(i, sz(cur), sz(cur) - m)
		sum += cur[i];
	maxn = max(maxn, 1.0 * sum / m);
	printf("%.15f %.15f\n", minn, maxn);
}

int main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
	#endif
	while(read())
		solve();
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define li long long
#define ld long double
#define x first
#define y second
#define pt pair<int, int>
#define pll pair<ll, ll>
#define forn(i, t) for(int i = 0; i < (t); i++)
#define fore(i, f, t) for(int i = (f); i < (t); i++)
#define forr(i, f, t) for(int i = (f) - 1; i >= (t); i--)
#define all(x) (x).begin(), (x).end()
#define ins insert

using namespace std;

const int INF = 2147483647;
const int MOD = 1000000007;
const li INF64 = 9223372036854775807;
const ld EPS = 1e-7;

mt19937 myrand(time(NULL));

const int N = 113;

int n, m, k, p;
int a[N];
set<int> used;
double tc[N];

bool read(){
	if(scanf("%d%d", &n, &k) != 2)
		return 0;
	m = n / k;
	used = set<int>();
	forn(i, n){
		scanf("%d", &a[i]);
		used.insert(i);
	}
	scanf("%d", &p);
	int t, sum;
	forn(i, p){
		sum = 0;
		forn(j, m){
			scanf("%d", &t);
			--t;
			used.erase(t);
			sum += a[t];
		}
		tc[i] = (1.0 * sum / m);
	}
	return 1;
}

void solve(){
	double minn = 1.0 * N * N * N, maxn = 0.0;

	forn(i, p){
		minn = min(minn, tc[i]);
		maxn = max(maxn, tc[i]);
	}

	vector<int> cur;

	for (auto it : used)
		cur.pb(a[it]);

	sort(all(cur));
	if (sz(cur) < m){
		printf("%.15f %.15f\n", minn, maxn);
		return;
	}

	int sum = 0;
	forn(i, m)
		sum += cur[i];
	minn = min(minn, 1.0 * sum / m);

	sum = 0;
	forr(i, sz(cur), sz(cur) - m)
		sum += cur[i];
	maxn = max(maxn, 1.0 * sum / m);
	printf("%.15f %.15f\n", minn, maxn);
}

int main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
	#endif
	while(read())
		solve();
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define li long long
#define ld long double
#define x first
#define y second
#define pt pair<int, int>
#define pll pair<ll, ll>
#define forn(i, t) for(int i = 0; i < (t); i++)
#define fore(i, f, t) for(int i = (f); i < (t); i++)
#define forr(i, f, t) for(int i = (f) - 1; i >= (t); i--)
#define all(x) (x).begin(), (x).end()
#define ins insert

using namespace std;

const int INF = 2147483647;
const int MOD = 1000000007;
const li INF64 = 9223372036854775807;
const ld EPS = 1e-7;

mt19937 myrand(time(NULL));

const int N = 113;

int n, m, k, p;
int a[N];
set<int> used;
double tc[N];

bool read(){
	if(scanf("%d%d", &n, &k) != 2)
		return 0;
	m = n / k;
	used = set<int>();
	forn(i, n){
		scanf("%d", &a[i]);
		used.insert(i);
	}
	scanf("%d", &p);
	int t, sum;
	forn(i, p){
		sum = 0;
		forn(j, m){
			scanf("%d", &t);
			--t;
			used.erase(t);
			sum += a[t];
		}
		tc[i] = (1.0 * sum / m);
	}
	return 1;
}

void solve(){
	double minn = 1.0 * N * N * N, maxn = 0.0;

	forn(i, p){
		minn = min(minn, tc[i]);
		maxn = max(maxn, tc[i]);
	}

	vector<int> cur;

	for (auto it : used)
		cur.pb(a[it]);

	sort(all(cur));
	if (sz(cur) < m || p == k){
		printf("%.15f %.15f\n", minn, maxn);
		return;
	}

	int sum = 0;
	forn(i, m)
		sum += cur[i];
	minn = min(minn, 1.0 * sum / m);

	sum = 0;
	forr(i, sz(cur), sz(cur) - m)
		sum += cur[i];
	maxn = max(maxn, 1.0 * sum / m);
	printf("%.15f %.15f\n", minn, maxn);
}

int main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
	#endif
	while(read())
		solve();
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include<queue>
#include <cmath>
#include <stack>
#include<iomanip>

using namespace std;

const int INF = INT_MAX / 2;

int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, k;
	scanf("%d %d", &n, &k);

	vector<int> a(n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	int q;
	scanf("%d", &q);
	vector<bool> used(n, false);

	double maxx = -INF, minn = INF;

	for(int i = 0; i < q; i++)
	{
		double sum = 0;
		for(int j = 0; j < n / k; j++)
		{
			int x;
			scanf("%d", &x);
			x--;
			used[x] = true;
			sum += a[x];
		}

		sum /= (n / k);
		minn = min(minn, sum);
		maxx = max(maxx, sum);
	}

	if(count(used.begin(), used.end(), true) == k * (n / k))
	{
		cout << setprecision(10) << fixed << minn << " " << maxx << endl;
		return 0;
	}

	vector<int> b;
	for(int i = 0; i < n; i++)
		if(!used[i])
			b.push_back(a[i]);

	sort(b.begin(), b.end());

	double sum = 0;
	for(int i = 0, cnt = 0; i < b.size(); i++)
	{
		sum += b[i];
		cnt++;

		if(cnt == n / k)
		{
			sum /= (n / k);
			minn = min(minn, sum);
			break;
		}
	}

	sum = 0;
	reverse(b.begin(), b.end());
	for(int i = 0, cnt = 0; i < b.size(); i++)
	{
		sum += b[i];
		cnt++;

		if(cnt == n / k)
		{
			sum /= (n / k);
			maxx = max(maxx, sum);
			break;
		}
	}

	cout << setprecision(10) << fixed << minn << " " << maxx << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include<queue>
#include <cmath>
#include <stack>
#include<iomanip>

using namespace std;

const int INF = INT_MAX / 2;

int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, k;
	scanf("%d %d", &n, &k);

	vector<int> a(n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	int q;
	scanf("%d", &q);
	vector<bool> used(n, false);

	double maxx = -INF, minn = INF;

	for(int i = 0; i < q; i++)
	{
		double sum = 0;
		for(int j = 0; j < n / k; j++)
		{
			int x;
			scanf("%d", &x);
			x--;
			used[x] = true;
			sum += a[x];
		}

		sum /= (n / k);
		minn = min(minn, sum);
		maxx = max(maxx, sum);
	}

	vector<bool> p(n, true);
	if(p == used)
	{
		cout << setprecision(10) << fixed << minn << " " << maxx << endl;
		return 0;
	}

	vector<int> b;
	for(int i = 0; i < n; i++)
		if(!used[i])
			b.push_back(a[i]);

	sort(b.begin(), b.end());

	double sum = 0;
	for(int i = 0, cnt = 0; i < b.size(); i++)
	{
		sum += b[i];
		cnt++;

		if(cnt == n / k)
		{
			sum /= (n / k);
			minn = min(minn, sum);
			break;
		}
	}

	sum = 0;
	reverse(b.begin(), b.end());
	for(int i = 0, cnt = 0; i < b.size(); i++)
	{
		sum += b[i];
		cnt++;

		if(cnt == n / k)
		{
			sum /= (n / k);
			maxx = max(maxx, sum);
			break;
		}
	}

	cout << setprecision(10) << fixed << minn << " " << maxx << endl;
}


/*  ^^ ====== ^^
ID: meixiuxiu
PROG: test
LANG: C++11
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
#include <cctype>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int ,int> pii;
#define MEM(a,b) memset(a,b,sizeof a)
#define CLR(a) memset(a,0,sizeof a);
#define pi acos(-1.0)
#define maxn 40000
#define maxv 100005
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
bool vis[maxv];
bool vis1[maxv];
int a[maxv];
int main()
{
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
    int n,k;cin >> n >> k;
    double nmax = 0,nmin = inf;
    for(int i=1;i<=n;i++)cin >> a[i];
    int q;cin >> q;
    int t = n/k;
    int b[maxv],c[maxv];
    double tot = 0;
    if(q){
        for(int i=1;i<=t;i++){
            cin >> b[i];
            tot += a[b[i]];
            vis[b[i]] = 1;
        }
        sort(b+1,b+1+t);
        tot /= t;
        nmax = max(nmax,tot);
        nmin = min(nmin,tot);
    }
    for(int i=2;i<=q;i++){
        tot = 0;
        for(int i=1;i<=t;i++){
            cin >> c[i];
            tot += a[c[i]];
            vis[c[i]] = 1;
        }
        sort(c+1,c+1+t);
        int ok = 0;
        for(int i=1;i<=t;i++){
            if(c[i]!=b[i])ok = 1;
        }
        if(!ok)continue;
        tot /= t;
        nmax = max(nmax,tot);
        nmin = min(nmin,tot);
    }
    std::vector<int> v;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            v.push_back(a[i]);
        }
    }
    sort(v.begin(),v.end());
    if((n-v.size()) / t < k){
        tot = 0;
        for(int i=0;i<t;i++)tot += v[i];
        tot /= t;
        nmax = max(nmax,tot);
        nmin = min(nmin,tot);
        int j = v.size()-1;
        tot = 0;
        for(int i=0;i<t;i++,j--){
            tot += v[j];
        }
        tot /= t;
        nmax = max(nmax,tot);
        nmin = min(nmin,tot);
    }
    printf("%.10lf %.10lf\n",nmin,nmax);
	return 0;
}


/*  ^^ ====== ^^
ID: meixiuxiu
PROG: test
LANG: C++11
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
#include <cctype>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int ,int> pii;
#define MEM(a,b) memset(a,b,sizeof a)
#define CLR(a) memset(a,0,sizeof a);
#define pi acos(-1.0)
#define maxn 40000
#define maxv 100005
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
bool vis[maxv];
bool vis1[maxv];
int a[maxv];
int main()
{
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
    int n,k;cin >> n >> k;
    double nmax = 0,nmin = inf;
    for(int i=1;i<=n;i++)cin >> a[i];
    int q;cin >> q;
    int t = n/k;
    int b[maxv],c[maxv];
    double tot = 0;
    for(int i=1;i<=t;i++){
        cin >> b[i];
        tot += a[b[i]];
        vis[b[i]] = 1;
    }
    sort(b+1,b+1+t);
    tot /= t;
    nmax = max(nmax,tot);
    nmin = min(nmin,tot);
    for(int i=2;i<=q;i++){
        tot = 0;
        for(int i=1;i<=t;i++){
            cin >> c[i];
            tot += a[c[i]];
            vis[c[i]] = 1;
        }
        sort(c+1,c+1+t);
        int ok = 0;
        for(int i=1;i<=t;i++){
            if(c[i]!=b[i])ok = 1;
        }
        if(!ok)continue;
        tot /= t;
        nmax = max(nmax,tot);
        nmin = min(nmin,tot);
    }
    std::vector<int> v;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            v.push_back(a[i]);
        }
    }
    sort(v.begin(),v.end());
    if(v.size()>=t){
        tot = 0;
        for(int i=0;i<t;i++)tot += v[i];
        tot /= t;
        nmax = max(nmax,tot);
        nmin = min(nmin,tot);
        int j = v.size()-1;
        tot = 0;
        for(int i=0;i<t;i++,j--){
           // cout << v[j] << endl;
            tot += v[j];
        }
        tot /= t;
        nmax = max(nmax,tot);
        nmin = min(nmin,tot);
    }
    printf("%.10lf %.10lf\n",nmin,nmax);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define FINAL_OUT(x) {cout << x << '\n'; return 0;}

int const maxn = 105;
int a[maxn];
int used[maxn];

int main()
{
//    freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    int cnt = n/k;
    double _min = 100.0;
    double _max = 0.0;
    int q = 0;
    cin >> q;
    int cnt_tick = 0;
    for(int i = 0; i < q; ++i)
    {
        double cur_sum = 0.0;
        for(int j = 0; j < cnt; ++j)
        {
            int tmp = 0;
            cin >> tmp;
            if (!used[tmp])
                ++cnt_tick;
            used[tmp] = 1;
            cur_sum += a[tmp];
        }
        cur_sum /= cnt;
        if (cur_sum > _max)
            _max = cur_sum;
        if (cur_sum < _min)
            _min = cur_sum;
    }
    cnt_tick /= cnt;

    vector<int> free_task;
    for(int i = 1; i <= n; ++i)
        if (!used[i])
            free_task.push_back(a[i]);
    sort(free_task.begin(), free_task.end());
    if (free_task.size() >= cnt && cnt_tick < k)
    {
        double cur_sum = 0.0;
        for(int i = 0; i < cnt; ++i)
            cur_sum += free_task[i];
        cur_sum /= cnt;
        if (cur_sum < _min)
            _min = cur_sum;
        cur_sum = 0;
        for(int i = 1; i <= cnt; ++i)
            cur_sum += free_task[free_task.size() - i];
        cur_sum /= cnt;
        if (cur_sum > _max)
            _max = cur_sum;
    }
    cout << setprecision(10);
    cout << fixed;
    cout << _min << ' '  << _max << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define FINAL_OUT(x) {cout << x << '\n'; return 0;}

int const maxn = 105;
int a[maxn];
int used[maxn];

int main()
{
//    freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    int cnt = n/k;
    double _min = 100.0;
    double _max = 0.0;
    int q = 0;
    cin >> q;
    for(int i = 0; i < q; ++i)
    {
        double cur_sum = 0.0;
        for(int j = 0; j < cnt; ++j)
        {
            int tmp = 0;
            cin >> tmp;
            used[tmp] = 1;
            cur_sum += a[tmp];
        }
        cur_sum /= cnt;
        if (cur_sum > _max)
            _max = cur_sum;
        if (cur_sum < _min)
            _min = cur_sum;
    }

    vector<int> free_task;
    for(int i = 1; i <= n; ++i)
        if (!used[i])
            free_task.push_back(a[i]);
    sort(free_task.begin(), free_task.end());
    if (free_task.size() >= cnt)
    {
        double cur_sum = 0.0;
        for(int i = 0; i < cnt; ++i)
            cur_sum += free_task[i];
        cur_sum /= cnt;
        if (cur_sum < _min)
            _min = cur_sum;
        cur_sum = 0;
        for(int i = 1; i <= cnt; ++i)
            cur_sum += free_task[free_task.size() - i];
        cur_sum /= cnt;
        if (cur_sum > _max)
            _max = cur_sum;
    }
    cout << setprecision(10);
    cout << fixed;
    cout << _min << ' '  << _max << '\n';
    return 0;
}


/* -*- coding: utf-8; tab-width: 4 -*- */

#include <cstdio>
#include <algorithm>

int
main()
{
	int n, k;
	int a[101];
	int q, c, v, u(0);
	double t, min(10000), max(0);

	std::scanf("%d%d", &n, &k);
	for (int i(0); i < n; ++i) std::scanf("%d", a + i);
	c = n / k;
	std::scanf("%d", &q);
	while (0 < q--) {
		t = 0;
		for (int i(0); i < c; ++i) {
			std::scanf("%d", &v);
			t += a[v-1];
			a[v-1] = -1;
		}
		if (0 <= t) {
			u += c;
			t /= c;
			if (t < min) min = t;
			if (max < t) max = t;
		}
	}

	if (c <= n - u) {
		std::stable_sort(a, a + n);
		t = 0;
		for (int i(0); i < c; ++i) t += a[u+i];
		min = std::min(min, t / c);
		t = 0;
		for (int i(0); i < c; ++i) t += a[n-i-1];
		max = std::max(max, t / c);
	}

	std::printf("%.8lf %.8lf\n", min, max);

	return 0;
}


/* -*- coding: utf-8; tab-width: 4 -*- */

#include <cstdio>
#include <algorithm>

int
main()
{
	int n, k;
	int a[101];
	int q, c, v, u(0);
	double t, min(10000), max(0);

	std::scanf("%d%d", &n, &k);
	for (int i(0); i < n; ++i) std::scanf("%d", a + i);
	c = n / k;
	std::scanf("%d", &q);
	while (0 < q--) {
		t = 0;
		for (int i(0); i < c; ++i) {
			std::scanf("%d", &v);
			t += a[v-1];
			a[v-1] = -1;
		}
		if (0 <= t) {
			u += c;
			t /= c;
			if (t < min) min = t;
			if (max < t) max = t;
		}
	}

	if (c <= n - u && u / c < k) {
		std::stable_sort(a, a + n);
		t = 0;
		for (int i(0); i < c; ++i) t += a[u+i];
		min = std::min(min, t / c);
		t = 0;
		for (int i(0); i < c; ++i) t += a[n-i-1];
		max = std::max(max, t / c);
	}

	std::printf("%.8lf %.8lf\n", min, max);

	return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

/** ----------STL shortcuts--------------*/

#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpll vector<pll>
#define vpii vector<pii>
#define PQ priority_queue
#define pb push_back
#define MP make_pair
#define UB upper_bound
#define LB lower_bound
#define F first
#define S second
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define all(v) v.begin(),v.end()
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())

            /** ---------------------Debugging---------------------*/

#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); deb(_it, args); }
void deb(istream_iterator<string> it) {}
template<typename T, typename... Args>
void deb(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    deb(++it, args...);
}
#define asche cerr<<"Ekhane asche\n";
#define what_is(x) cerr << #x << " is " << x << endl
#define printa(a,L,R) for(int i=L;i<R;i++) cout<<a[i]<<(i==R-1?'\n':' ')
#define printv(a) printa(a,0,a.size())
#define print2d(a,r,c) for(int i=0;i<r;i++) for(int j=0;j<c;j++) cout<<a[i][j]<<(j==c-1?'\n':' ')

            /** -------------------Other utilities---------------------*/

#define SQ(x) ((x)*(x))
#define issq(x) (((ll)(sqrt((x))))*((ll)(sqrt((x))))==(x))
#define mem(a,x) memset(a,x,sizeof(a))
#define inf 1e18
#define PI (acos(-1.0))
#define nl "\n"
#define lg(r,n) (int)(log2(n)/log2(r))
#define fast ios_base::sync_with_stdio(false)
#define one(x) __builtin_popcount(x)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define stree ll l=(n<<1),r=l+1,mid=b+(e-b)/2
#define fout(x) fixed<<setprecision(x)
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
#define toint(a) atoi(a.c_str())
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end));i != (end) - ((begin) > (end));i += 1 - 2 * ((begin) > (end)))

//ll dx[]={1,0,-1,0,1,-1,-1,1};
//ll dy[]={0,1,0,-1,1,1,-1,-1};
#define valid(tx,ty) (tx>=0&&tx<n&&ty>=0&&ty<m)
//ll gcd(ll a,ll b){while(b){ll x=a%b;a=b;b=x;}return a;}
//ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}
const int mod=1e9+7;
const int mxn=3e5+9;
const ld eps=1e-9;

/**-------------------------------------------------------------------------------------------------------*/

int main()
{
    int n,k,q,koyta;
    cin>>n>>k;
    vi a(n+2);
    vector<bool>f(n+2,false);
    koyta = n/k;
    for(int i=1;i<=n;i++) cin>>a[i];
    cin>>q;
    vector <double>effi;
    for(int j=0;j<q;j++){
        ll sum =0;bool flag=false;
        for(int i=0,x;i<koyta;i++){
            cin>>x;
            if(f[x]) flag = true;
            f[x] = true;
            sum += a[x];
        }
        if(!flag) effi.push_back((sum*1.0)/koyta);
    }
    srt(effi);
    vi baki;
    for(int i=1;i<=n;i++){
        if(!f[i]) baki.push_back(a[i]);
    }
    cout<<fixed<<setprecision(10);
    srt(baki);
    if((baki.size() < koyta && effi.size() > 0) || (effi.size()==k)){
        return cout<<effi[0]<<' '<<effi[effi.size()-1]<<nl, 0;
    }
    ll Maxx = 0, Minn = 0;
    for(int i=0, j = baki.size()-1;i<koyta;i++,j--){
        Minn += baki[i];
        Maxx += baki[j];
    }
    effi.push_back((Minn*1.0)/koyta);
    effi.push_back((Maxx*1.0)/koyta);
    srt(effi);
    cout<<effi[0]<<' '<<effi[effi.size()-1]<<nl;
    return 0;
}


/*
I don't want to go home
I'm feeling like a ghost
I'm falling all apart
Could you please fix my heart?

Why don't we leave this old town?
A new world waits to be seen
Give me a reason to stay
I'm not afraid to live

Tell me now
What do you read in my hand
Please don't spell me wrong
What is going on?

Tell me now
What is seen from my hand
I know what is true
Nothing's really new

Why don't we leave this old town?
A new world waits to be seen
Give me a reason to stay
I'm not afraid to live

Tell me now
All my will and destiny
Won't erase my hand
It won't change my plans

Tell me now
What could be the best for me
It's always been the same
I'm running like a train

I don't want to go home
I'm feeling like a ghost
I'm falling all apart
Could you please fix my heart?

Why don't we leave this old town?
A new world waits to be seen
Give me a reason to stay
I'm not afraid to live

Here we go
No one said it was easy
I'm on my feet again
A ticket in my hand

Here we go, here we go
Here we go, here we go
*/

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <ctime>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define eps 1e-9
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 512
#define time asdfasdfasfd

using namespace std;

int n,k,ar[1000];
double l,r;
int one,ttl;
vector<int> v;
int used[1<<20];

int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//freopen("F:/in.txt","r",stdin);
//freopen("F:/output.txt","w",stdout);
ios_base::sync_with_stdio(0);
//cin.tie(0);

cin>>n>>k;
for (int i=1;i<=n;i++)
{
    cin>>ar[i];
}

l=1e9;
r=-1e9;

one=n/k;

cin>>ttl;
int T=ttl;
for (;ttl;--ttl)
{
    int s=0;
    for (int i=1;i<=one;i++)
    {
        int val;
        cin>>val;
        used[val]=1;
        s+=ar[val];
    }
    l=min(l,s*1.0/one);
    r=max(r,s*1.0/one);
}

if (T<k)
{

for (int i=1;i<=n;i++)
{
    if (used[i]==0)
        v.push_back(ar[i]);
}
sort(v.begin(),v.end());

int s=0;
for (int i=0;i<one;i++)
{
    s+=v[i];
}

l=min(l,s*1.0/one);
r=max(r,s*1.0/one);
reverse(v.begin(),v.end());
s=0;
for (int i=0;i<one;i++)
{
    s+=v[i];
}

l=min(l,s*1.0/one);
r=max(r,s*1.0/one);
}

cout.precision(10);
cout<<fixed<<l<<" "<<r<<endl;

//cin.get();cin.get();
return 0;}


/*
I don't want to go home
I'm feeling like a ghost
I'm falling all apart
Could you please fix my heart?

Why don't we leave this old town?
A new world waits to be seen
Give me a reason to stay
I'm not afraid to live

Tell me now
What do you read in my hand
Please don't spell me wrong
What is going on?

Tell me now
What is seen from my hand
I know what is true
Nothing's really new

Why don't we leave this old town?
A new world waits to be seen
Give me a reason to stay
I'm not afraid to live

Tell me now
All my will and destiny
Won't erase my hand
It won't change my plans

Tell me now
What could be the best for me
It's always been the same
I'm running like a train

I don't want to go home
I'm feeling like a ghost
I'm falling all apart
Could you please fix my heart?

Why don't we leave this old town?
A new world waits to be seen
Give me a reason to stay
I'm not afraid to live

Here we go
No one said it was easy
I'm on my feet again
A ticket in my hand

Here we go, here we go
Here we go, here we go
*/

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <ctime>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define eps 1e-9
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 512
#define time asdfasdfasfd

using namespace std;

int n,k,ar[1000];
double l,r;
int one,ttl;
vector<int> v;
int used[1<<20];

int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//freopen("F:/in.txt","r",stdin);
//freopen("F:/output.txt","w",stdout);
ios_base::sync_with_stdio(0);
//cin.tie(0);

cin>>n>>k;
for (int i=1;i<=n;i++)
{
    cin>>ar[i];
}

l=1e9;
r=-1e9;

one=n/k;

cin>>ttl;
int T=ttl;
for (;ttl;--ttl)
{
    int s=0;
    int unique=1;
    for (int i=1;i<=one;i++)
    {
        int val;
        cin>>val;
        if (used[val])
            unique=0;
        used[val]=1;
        s+=ar[val];
    }
    l=min(l,s*1.0/one);
    r=max(r,s*1.0/one);
    if (unique==0)
        --T;
}

if (T<k)
{

for (int i=1;i<=n;i++)
{
    if (used[i]==0)
        v.push_back(ar[i]);
}
sort(v.begin(),v.end());

int s=0;
for (int i=0;i<one;i++)
{
    s+=v[i];
}

l=min(l,s*1.0/one);
r=max(r,s*1.0/one);
reverse(v.begin(),v.end());
s=0;
for (int i=0;i<one;i++)
{
    s+=v[i];
}

l=min(l,s*1.0/one);
r=max(r,s*1.0/one);
}

cout.precision(10);
cout<<fixed<<l<<" "<<r<<endl;

//cin.get();cin.get();
return 0;}


#include <bits/stdc++.h>

#if (_WIN32 || __WIN32__)
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

using std::istream; using std::ostream; using std::fixed; using std::greater;
using std::tuple; using std::tie; using std::make_pair; using std::multiset;
using std::nth_element; using std::min_element; using std::max_element;
using std::vector; using std::set; using std::map; using std::string;
using std::fill; using std::copy; using std::sort; using std::unique;
using std::unordered_set; using std::unordered_map; using std::pair;
using std::next_permutation; using std::reverse; using std::rotate;
using std::cin; using std::cout; using std::cerr; using std::endl;
using std::lower_bound; using std::upper_bound; using std::deque;
using std::min; using std::max; using std::swap; using std::abs;
using std::priority_queue; using std::queue; using std::bitset;
using std::make_tuple; using std::iota;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;

ll rnd(ll x, ll y) { static auto gen = std::bind(std::uniform_int_distribution<ll>(), std::mt19937(960172)); return gen() % (y - x + 1) + x; }
ll gcd(ll a, ll b) { while (b > 0) { ll t = a % b; a = b; b = t; } return a; }
template<typename T> T sqr(T const& a) { return a * a; }

int const INF = 100 + (int) 1e9;
ll const INFL = 100 + (ll) 1e18;
ld const PI = 3.1415926535897932384626433832795028;

void solve() {

	int n, k;
	scanf("%d%d", &n, &k);

	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}

	multiset<int> th;
	for (int x : a) th.insert(x);

	int q;
	scanf("%d", &q);

	set<multiset<int>> ts;

	while (q--) {
		multiset<int> cur;
		for (int i = 0; i < n / k; ++i) {
			int x;
			scanf("%d", &x);
			cur.insert(a[x - 1]);
		}
		ts.insert(cur);
	}

	int mi = INF;
	int ma = -INF;

	for (auto t : ts) {
		int sum = 0;
		for (int x : t) {
			th.erase(th.find(x));
			sum += x;
		}
		mi = min(mi, sum);
		ma = max(ma, sum);
	}

	vector<int> rest(th.begin(), th.end());

	if ((int)rest.size() >= n / k) {
		for (int it = 0; it < 2; ++it) {
			int sum = 0;
			for (int i = 0; i < n / k; ++i) {
				sum += rest[i];
			}
			mi = min(mi, sum);
			ma = max(ma, sum);
			reverse(rest.begin(), rest.end());
		}
	}

	cout << (double) mi / (n / k) << " " << (double) ma / (n / k) << endl;

}

int main() {

	cout.precision(15);
	cout << fixed;
	cerr.precision(6);
	cerr << fixed;

	solve();

#ifdef LOCAL
	cerr << "time: " << (ll) clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#endif
}


#include <bits/stdc++.h>

#if (_WIN32 || __WIN32__)
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

using std::istream; using std::ostream; using std::fixed; using std::greater;
using std::tuple; using std::tie; using std::make_pair; using std::multiset;
using std::nth_element; using std::min_element; using std::max_element;
using std::vector; using std::set; using std::map; using std::string;
using std::fill; using std::copy; using std::sort; using std::unique;
using std::unordered_set; using std::unordered_map; using std::pair;
using std::next_permutation; using std::reverse; using std::rotate;
using std::cin; using std::cout; using std::cerr; using std::endl;
using std::lower_bound; using std::upper_bound; using std::deque;
using std::min; using std::max; using std::swap; using std::abs;
using std::priority_queue; using std::queue; using std::bitset;
using std::make_tuple; using std::iota;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;

ll rnd(ll x, ll y) { static auto gen = std::bind(std::uniform_int_distribution<ll>(), std::mt19937(960172)); return gen() % (y - x + 1) + x; }
ll gcd(ll a, ll b) { while (b > 0) { ll t = a % b; a = b; b = t; } return a; }
template<typename T> T sqr(T const& a) { return a * a; }

int const INF = 100 + (int) 1e9;
ll const INFL = 100 + (ll) 1e18;
ld const PI = 3.1415926535897932384626433832795028;

void solve() {

	int n, k;
	scanf("%d%d", &n, &k);

	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}

	multiset<int> th;
	for (int x : a) th.insert(x);

	int q;
	scanf("%d", &q);

	set<multiset<int>> ts;

	while (q--) {
		multiset<int> cur;
		for (int i = 0; i < n / k; ++i) {
			int x;
			scanf("%d", &x);
			cur.insert(a[x - 1]);
		}
		ts.insert(cur);
	}

	int mi = INF;
	int ma = -INF;

	for (auto t : ts) {
		int sum = 0;
		for (int x : t) {
			th.erase(th.find(x));
			sum += x;
		}
		mi = min(mi, sum);
		ma = max(ma, sum);
	}

	vector<int> rest(th.begin(), th.end());

	if ((int)rest.size() >= n / k && (int)ts.size() < k) {
		for (int it = 0; it < 2; ++it) {
			int sum = 0;
			for (int i = 0; i < n / k; ++i) {
				sum += rest[i];
			}
			mi = min(mi, sum);
			ma = max(ma, sum);
			reverse(rest.begin(), rest.end());
		}
	}

	cout << (double) mi / (n / k) << " " << (double) ma / (n / k) << endl;

}

int main() {

	cout.precision(15);
	cout << fixed;
	cerr.precision(6);
	cerr << fixed;

	solve();

#ifdef LOCAL
	cerr << "time: " << (ll) clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#endif
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 100;
int n, k, q, a[N];
bool vis[N];
vector<int> v;

int main() {
//  freopen("a", "r", stdin);
    scanf("%d%d", &n, &k);
    int m = n / k;
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &q);
    while (q--) {
        int sum = 0;
        for (int i = 0, x; i < m; ++i) {
            scanf("%d", &x);
            --x;
            sum += a[x];
            vis[x] = true;
        }
        v.push_back(sum);
    }
    sort(v.begin(), v.end());
    int mn = 2e9, mx = 0, out = n - k * m;
    if (!v.empty()) {
        mn = v[0];
        mx = v.back();
    }
    vector<int> vv;
    for (int i = 0; i < n; ++i)
        if (!vis[i])
            vv.push_back(a[i]);
    if ((int) vv.size() - m >= out) {
        sort(vv.begin(), vv.end());
        int sum = 0;
        for (int i = 0; i < m; ++i)
            sum += vv[i];
        mn = min(mn, sum);
        int need = m;
        sum = 0;
        while (need--) {
            sum += vv.back();
            vv.pop_back();
        }
        mx = max(mx, sum);
    }
    printf("%.10lf %.10lf\n", mn * 1.0 / m, mx * 1.0 / m);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sc(x)  scanf("%d",&x)
#define sc2(x,y)  scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define F first
#define S second
#define pb push_back
#define pi 3.1415926535897932384
//ios::sync_with_stdio(0);
//  cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int main()
{
    int n,k;
    cin>>n>>k;
    int z=n/k;
    int x[n];
    bool b[110]= {0};
    vector<double>v;
    vector<int>vv;
    for (int i=0 ; i<n ; i++) cin>>x[i];
    int q;
    cin>>q;
    while(q--)
    {
        int y=z;
        double s=0;
        while (y--)
        {
            int xx;
            cin>>xx;
            xx--;
            s+=x[xx];
            b[xx]=1;
        }
        v.pb(s/z);
    }
    for (int i=0 ; i<n ; i++) if(!b[i]) vv.pb(x[i]);
    if (n-vv.size()<z*k)
    {
        sort(vv.begin(),vv.end());
        double s=0;
        for (int i=0 ; i<z ; i++)
            s+=vv[i];
        v.pb(s/z);
        s=0;
        for (int i=vv.size()-1 ; vv.size()-i<=z ; i--)
            s+=vv[i];
        v.pb(s/z);
    }
    sort(v.begin(),v.end());
    cout<<setprecision(6)<<fixed<<v.front()<<" "<<v.back()<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sc(x)  scanf("%d",&x)
#define sc2(x,y)  scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define F first
#define S second
#define pb push_back
#define pi 3.1415926535897932384
//ios::sync_with_stdio(0);
//  cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int main()
{
    int n,k;
    cin>>n>>k;
    int z=n/k;
    int x[n];
    bool b[110]= {0};
    vector<double>v;
    vector<int>vv;
    for (int i=0 ; i<n ; i++) cin>>x[i];
    int q;
    cin>>q;
    while(q--)
    {
        int y=z;
        double s=0;
        while (y--)
        {
            int xx;
            cin>>xx;
            xx--;
            s+=x[xx];
            b[xx]=1;
        }
        v.pb(s/z);
    }
    for (int i=0 ; i<n ; i++) if(!b[i]) vv.pb(x[i]);
    if (n-vv.size()<z*k)
    {
        sort(vv.begin(),vv.end());
        double s=0;
        for (int i=0 ; i<z ; i++)
            s+=vv[i];
        v.pb(s/z);
        s=0;
        cout<<vv.size()<<endl;
        for (int i=vv.size()-1 ; vv.size()-i<=z ; i--)
            s+=vv[i];
        v.pb(s/z);
    }
    cout<<setprecision(6)<<fixed<<v.front()<<" "<<v.back()<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sc(x)  scanf("%d",&x)
#define sc2(x,y)  scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define F first
#define S second
#define pb push_back
#define pi 3.1415926535897932384
//ios::sync_with_stdio(0);
//  cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int main()
{
    int n,k;
    cin>>n>>k;
    int z=n/k;
    int x[n];
    bool b[110]= {0};
    vector<double>v;
    vector<int>vv;
    for (int i=0 ; i<n ; i++) cin>>x[i];
    int q;
    cin>>q;
    while(q--)
    {
        int y=z;
        double s=0;
        while (y--)
        {
            int xx;
            cin>>xx;
            xx--;
            s+=x[xx];
            b[xx]=1;
        }
        v.pb(s/z);
    }
    for (int i=0 ; i<n ; i++) if(!b[i]) vv.pb(x[i]);
    if (n-vv.size()<z*k)
    {
        sort(vv.begin(),vv.end());
        double s=0;
        for (int i=0 ; i<z ; i++)
            s+=vv[i];
        v.pb(s/z);
        s=0;
        cout<<vv.size()<<endl;
        for (int i=vv.size()-1 ; vv.size()-i<=z ; i--)
            s+=vv[i];
        v.pb(s/z);
    }
    sort(v.begin(),v.end());
    cout<<setprecision(6)<<fixed<<v.front()<<" "<<v.back()<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sc(x)  scanf("%d",&x)
#define sc2(x,y)  scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define F first
#define S second
#define pb push_back
#define pi 3.1415926535897932384
//ios::sync_with_stdio(0);
//  cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
int main()
{
    int n,k;
    cin>>n>>k;
    int z=n/k;
    pair<int,int> x[n];
    bool b[110]={0};
    vector<double>v;
    for (int i=0 ; i<n ; i++) cin>>x[i].F,x[i].S=i;
    int q;
    cin>>q;
    while(q--)
    {
        int y=z;
        double s=0;
        while (y--)
        {
            int xx;
            cin>>xx;
            xx--;
            s+=x[xx].F;
            b[xx]=1;
        }
        v.pb(s/z);
    }
    sort(x,x+n);
    double s=0,c=z;
    for (int i=0 ; i<n && c ; i++)
        if (!b[x[i].S])
            s+=x[i].F,c--;
    if (!c) v.pb(s/z);
    s=0,c=z;
    for (int i=n-1 ; i>=0 && c ; i--)
        if (!b[x[i].S])
            s+=x[i].F,c--;
    if (!c) v.pb(s/z);
    sort(v.begin(),v.end());
    cout<<setprecision(6)<<fixed<<v.front()<<" "<<v.back()<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sc(x)  scanf("%d",&x)
#define sc2(x,y)  scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define F first
#define S second
#define pb push_back
#define pi 3.1415926535897932384
//ios::sync_with_stdio(0);
//  cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int main()
{
    int n,k;
    cin>>n>>k;
    int z=n/k;
    int x[n];
    bool b[110]= {0};
    vector<double>v;
    vector<int>vv;
    for (int i=0 ; i<n ; i++) cin>>x[i];
    int q;
    cin>>q;
    while(q--)
    {
        int y=z;
        double s=0;
        while (y--)
        {
            int xx;
            cin>>xx;
            xx--;
            s+=x[xx];
            b[xx]=1;
        }
        v.pb(s/z);
    }
    for (int i=0 ; i<n ; i++) if(!b[i]) vv.pb(x[i]);
    if (n-vv.size()<z*k)
    {
        sort(vv.begin(),vv.end());
        double s=0;
        for (int i=0 ; i<z ; i++)
            s+=vv[i];
               v.pb(s/z);
        s=0;
        for (int i=v.size()-1 ; v.size()-z>=0 ; i--)
            s+=vv[i];
        v.pb(s/z);
    }
    sort(v.begin(),v.end());
    cout<<setprecision(6)<<fixed<<v.front()<<" "<<v.back()<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sc(x)  scanf("%d",&x)
#define sc2(x,y)  scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define F first
#define S second
#define pb push_back
#define pi 3.1415926535897932384
//ios::sync_with_stdio(0);
//  cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int main()
{
    int n,k;
    cin>>n>>k;
    int z=n/k;
    int x[n];
    bool b[110]= {0};
    vector<double>v;
    vector<int>vv;
    for (int i=0 ; i<n ; i++) cin>>x[i];
    int q;
    cin>>q;
    while(q--)
    {
        int y=z;
        double s=0;
        while (y--)
        {
            int xx;
            cin>>xx;
            xx--;
            s+=x[xx];
            b[xx]=1;
        }
        v.pb(s/z);
    }
    for (int i=0 ; i<n ; i++) if(!b[i]) vv.pb(x[i]);
    if (n-vv.size()<z*k)
    {
        sort(vv.begin(),vv.end());
        double s=0;
        for (int i=0 ; i<z ; i++)
            s+=vv[i];
        v.pb(s/z);
        s=0;
        for (int i=v.size()-1 ; i+1-z>=0 ; i--)
            s+=vv[i];
        v.pb(s/z);
    }
    sort(v.begin(),v.end());
    cout<<setprecision(6)<<fixed<<v.front()<<" "<<v.back()<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 110;
int a[maxn], b[110];
bool vis[maxn];

int main(){
	int n, k;
	cin>>n>>k;
	int m = n/k;
	if(n/k - m > 0.9999999) m++;
	for(int i = 1;i<=n;i++)	cin>>a[i];
	int q;
	cin>>q;
	int minn = INF, maxx = -INF;
	memset(vis, false, sizeof vis);
	int sum = 0;
	while(q--){
		int sum = 0;
		for(int i = 0;i<m;i++){
			int x;
			cin>>x;
			vis[x] = true;
			sum += a[x];
		}
		minn = min(minn, sum);
		maxx = max(maxx, sum);
	}
	int cnt = 0;
	for(int i = 1;i<=n;i++){
		if(!vis[i]){
			b[cnt++] = a[i];
		}
	}
	sort(b, b+cnt);
	if(cnt >= m){
		sum = 0;
		for(int i = 0;i<m;i++)	sum += b[i];
		minn = min(minn, sum);
		sum = 0;
		for(int i = cnt-1;i>=cnt-m;i--)	sum += b[i];
		maxx = max(maxx, sum);
	}
	double ans1 = minn*1.0/(m*1.0);
	double ans2 = maxx*1.0/(m*1.0);
	printf("%.10lf %.10lf\n", ans1, ans2);
	return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 110;
int a[maxn], b[110];
bool vis[maxn];
set<int>S;
int main(){
	int n, k;
	cin>>n>>k;
	int m = n/k;
	if(n/k - m > 0.9999999) m++;
	for(int i = 1;i<=n;i++)	cin>>a[i];
	int q;
	cin>>q;
	int minn = INF, maxx = -INF;
	memset(vis, false, sizeof vis);
	int sum = 0;
	int hehe = 0;
	for(int i = 0;i<q;i++){
		int sum = 0;
		bool f = false;
		for(int i = 0;i<m;i++){
			int x;
			cin>>x;
			if(!vis[x]&&!f){
				hehe++;
				f= true;
			}
			vis[x] = true;
			sum += a[x];
		}
		minn = min(minn, sum);
		maxx = max(maxx, sum);
	}
	int cnt = 0;
	for(int i = 1;i<=n;i++){
		if(!vis[i]){
			b[cnt++] = a[i];
		}
	}
	sort(b, b+cnt);
	if(cnt >= m && k!=hehe){
		sum = 0;
		for(int i = 0;i<m;i++)	sum += b[i];
		minn = min(minn, sum);
		sum = 0;
		for(int i = cnt-1;i>=cnt-m;i--)	sum += b[i];
		maxx = max(maxx, sum);

	}
	double ans1 = minn*1.0/(m*1.0);
	double ans2 = maxx*1.0/(m*1.0);
	printf("%.10lf %.10lf\n", ans1, ans2);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 100;
int n, k, q, a[N];
bool vis[N];
vector<int> v;

int main() {
//  freopen("a", "r", stdin);
    scanf("%d%d", &n, &k);
    int m = n / k;
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &q);
    while (q--) {
        int sum = 0;
        for (int i = 0, x; i < m; ++i) {
            scanf("%d", &x);
            --x;
            sum += a[x];
            vis[x] = true;
        }
        v.push_back(sum);
    }
    sort(v.begin(), v.end());
    int mn = v[0], mx = v.back(), out = n - k * m;
    vector<int> vv;
    for (int i = 0; i < n; ++i)
        if (!vis[i])
            vv.push_back(a[i]);
    if ((int) vv.size() - m >= out) {
        sort(vv.begin(), vv.end());
        int sum = 0;
        for (int i = 0; i < m; ++i)
            sum += vv[i];
        mn = min(mn, sum);
        int need = m;
        sum = 0;
        while (need--) {
            sum += vv.back();
            vv.pop_back();
        }
        mx = max(mx, sum);
    }
    printf("%.10lf %.10lf\n", mn * 1.0 / m, mx * 1.0 / m);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ff(i,s,e) for(int i=(s);i<(int)(e);i++)
#define fr(i,s,e) for(int i=(e);i-->(int)(s);)
#define FF(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define Fr(i,s,e) for(int i=(e);i>=(int)(s);i--)

#define gcd(a,b) __gcd(a,b)
#define all(a) a.begin(),a.end()
#define ln putchar('\n')
#define sp putchar(' ')
using namespace __gnu_pbds;
using namespace std;

void init(int i){
#ifndef ONLINE_JUDGE
  char str[100];sprintf(str,"xx/%d.txt",i);freopen(str,"r",stdin);
#endif
}

typedef tree<int,int,less<int>,rb_tree_tag,tree_order_statistics_node_update>imap;

typedef long long ll;

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;

template<class T>inline int pr(const T&v);
template<class T, class...Args> inline int pr(const T&a,const Args (&... args));

inline int scan(int&i){return scanf("%d",&i);}
inline int scan(ll&i){return scanf("%" PRId64,&i);}
inline int scan(double&i){return scanf("%lf",&i);}
inline int scan(char&i){int c;while((c=getchar())!=EOF&&c<=' ');i=c;return c!=EOF;}
inline int scan(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<=' ');while(c>' ')i+=c,c=getchar();return i.size();}
inline int scanln(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<' ');while(c>=' ')i+=c,c=getchar();return i.size();}
template<class T> inline int scan(T&a){a.sc();}
template<class T, class U> inline int scan(pair<T,U>&a){scan(a.first),scan(a.second);}

inline int pr(const int& i){printf("%d",i);}
inline int pr(const long& i){printf("%ld",i);}
inline int pr(const unsigned int& i){printf("%x",i);}
inline int pr(const bool i){printf("%d",i);}
inline int pr(const ll&i){printf("%" PRId64,i);}
inline int pr(const double&i){printf("%.12f",i);}
inline int pr(const float&i){printf("%.4f",i);}
inline int pr(const char&i){putchar(i);}
inline int pr(const char*i){printf("%s",i);}
inline int pr(const string&i){for(char c:i)pr(c);}

template<class T>inline int scan(vector<T>&v){for(T&i:v)scan(i);}
template<class T>inline int pr(const vector<T>&v){if(v.empty())return 0;pr(v[0]);ff(i,1,v.size())pr(' '),pr(v[i]);}
template<class T,class U>inline int pr(const pair<T,U>&p){pr(p.first,p.second);}
template<class T>inline int prlns(const vector<T>&v){ff(i,0,v.size())pr(v[i]),pr('\n');}
template<class T, class...Args> inline int scan(T&a,Args (&... args)){return scan(a),scan(args...);}
template<class T, class...Args> inline int pr(const T&a,const Args (&... args)){pr(a),pr(' '),pr(args...);}
template<class T> inline int prln(const T&a){pr(a),ln;}
template<class T, class...Args> inline int prln(const T&a,const Args (&... args)){pr(a),sp,prln(args...);}
template<class...Args> inline int rpr(const Args (&... args)){
#ifndef ONLINE_JUDGE
  pr(args...),ln;fflush(stdout);
#endif
}
inline int gi(){int x;scan(x);return x;}

template<class T>inline int pr(const T&v){v.print();}

template<class T, class U> inline void smax(T&a,const U&b){if(a<b)a=b;}
template<class T, class U> inline void smin(T&a,const U&b){if(b<a)a=b;}

template<class T> T& operator +=(vector<T>&v,const T&a){v.push_back(a);return v.back();}

const int inf = ~((1<<31));
const ll LargeMod = 4611686018427388039;
const ll MOD = 1E9+7;
const ll linf = 1E17;
typedef unsigned int uint;

struct problem{
  int n, k;
  int sz;
  vi v;
  set<pii> m;
  int solve() {
    double ma = 0, mi = 1E9;
    int q = gi();
    ff(xx,0,q){
      double res = 0;
      ff(ll,0,sz){
        int t = gi() - 1;
        int val = v[t];
        m.erase({val, t});
        res += val;
      }
      if (res == -1)continue;
      smax(ma, res/sz);
      smin(mi, res/sz);
    }
    if ((n - m.size()) / sz < k) {
      auto k = m.begin();
      double res = 0;
      ff(i,0,sz)res += k->first, k++;
      smin(mi, res/sz);
      res = 0;
      k = m.end();
      ff(i,0,sz)res+=(--k)->first;
      smax(ma, res/sz);
    }
    pr(mi, ma);
  }
  int init(){

  }

  int get_input(){
    scan(n, k);
    sz = n/k;
    v.resize(n);
    ff(i,0,n){
      int t = gi();
      m.insert({t, i});
      v[i] = t;
    }
  }
};

main(){
  init(1);
  problem a;
  a.get_input();
  a.init();
  a.solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ff(i,s,e) for(int i=(s);i<(int)(e);i++)
#define fr(i,s,e) for(int i=(e);i-->(int)(s);)
#define FF(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define Fr(i,s,e) for(int i=(e);i>=(int)(s);i--)

#define gcd(a,b) __gcd(a,b)
#define all(a) a.begin(),a.end()
#define ln putchar('\n')
#define sp putchar(' ')
using namespace __gnu_pbds;
using namespace std;

void init(int i){
#ifndef ONLINE_JUDGE
  char str[100];sprintf(str,"xx/%d.txt",i);freopen(str,"r",stdin);
#endif
}

typedef tree<int,int,less<int>,rb_tree_tag,tree_order_statistics_node_update>imap;

typedef long long ll;

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;

template<class T>inline int pr(const T&v);
template<class T, class...Args> inline int pr(const T&a,const Args (&... args));

inline int scan(int&i){return scanf("%d",&i);}
inline int scan(ll&i){return scanf("%" PRId64,&i);}
inline int scan(double&i){return scanf("%lf",&i);}
inline int scan(char&i){int c;while((c=getchar())!=EOF&&c<=' ');i=c;return c!=EOF;}
inline int scan(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<=' ');while(c>' ')i+=c,c=getchar();return i.size();}
inline int scanln(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<' ');while(c>=' ')i+=c,c=getchar();return i.size();}
template<class T> inline int scan(T&a){a.sc();}
template<class T, class U> inline int scan(pair<T,U>&a){scan(a.first),scan(a.second);}

inline int pr(const int& i){printf("%d",i);}
inline int pr(const long& i){printf("%ld",i);}
inline int pr(const unsigned int& i){printf("%x",i);}
inline int pr(const bool i){printf("%d",i);}
inline int pr(const ll&i){printf("%" PRId64,i);}
inline int pr(const double&i){printf("%.12f",i);}
inline int pr(const float&i){printf("%.4f",i);}
inline int pr(const char&i){putchar(i);}
inline int pr(const char*i){printf("%s",i);}
inline int pr(const string&i){for(char c:i)pr(c);}

template<class T>inline int scan(vector<T>&v){for(T&i:v)scan(i);}
template<class T>inline int pr(const vector<T>&v){if(v.empty())return 0;pr(v[0]);ff(i,1,v.size())pr(' '),pr(v[i]);}
template<class T,class U>inline int pr(const pair<T,U>&p){pr(p.first,p.second);}
template<class T>inline int prlns(const vector<T>&v){ff(i,0,v.size())pr(v[i]),pr('\n');}
template<class T, class...Args> inline int scan(T&a,Args (&... args)){return scan(a),scan(args...);}
template<class T, class...Args> inline int pr(const T&a,const Args (&... args)){pr(a),pr(' '),pr(args...);}
template<class T> inline int prln(const T&a){pr(a),ln;}
template<class T, class...Args> inline int prln(const T&a,const Args (&... args)){pr(a),sp,prln(args...);}
template<class...Args> inline int rpr(const Args (&... args)){
#ifndef ONLINE_JUDGE
  pr(args...),ln;fflush(stdout);
#endif
}
inline int gi(){int x;scan(x);return x;}

template<class T>inline int pr(const T&v){v.print();}

template<class T, class U> inline void smax(T&a,const U&b){if(a<b)a=b;}
template<class T, class U> inline void smin(T&a,const U&b){if(b<a)a=b;}

template<class T> T& operator +=(vector<T>&v,const T&a){v.push_back(a);return v.back();}

const int inf = ~((1<<31));
const ll LargeMod = 4611686018427388039;
const ll MOD = 1E9+7;
const ll linf = 1E17;
typedef unsigned int uint;

struct problem{
  int n, k;
  int sz;
  vi v;
  set<pii> m;
  int solve() {
    double ma = 0, mi = 1E9;
    int q = gi();
    ff(xx,0,q){
      double res = 0;
      ff(ll,0,sz){
        int t = gi() - 1;
        int val = v[t];
        if (!m.count({val, t})){
          res = -1;
          break;
        }
        m.erase({val, t});
        res += val;
      }
      if (res == -1)continue;
      smax(ma, res/sz);
      smin(mi, res/sz);
    }
    if (m.size() >= sz) {
      auto k = m.begin();
      double res = 0;
      ff(i,0,sz)res += k->first, k++;
      smin(mi, res/sz);
      res = 0;
      k = m.end();
      ff(i,0,sz)res+=(--k)->first;
      smax(ma, res/sz);
    }
    pr(mi, ma);
  }
  int init(){

  }

  int get_input(){
    scan(n, k);
    sz = n/k;
    v.resize(n);
    ff(i,0,n){
      int t = gi();
      m.insert({t, i});
      v[i] = t;
    }
  }
};

main(){
  init(1);
  problem a;
  a.get_input();
  a.init();
  a.solve();
}