Skip to content

Instantly share code, notes, and snippets.

@taruta811
Created October 14, 2011 18:03
Show Gist options
  • Save taruta811/1287841 to your computer and use it in GitHub Desktop.
Save taruta811/1287841 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding:utf-8
import itertools
import sys
n,k = map(int,raw_input().split())
a = map(int,raw_input().split())
q = input()
qs = []
ll = n/k
remain = k
for i in range(q):
l = map(lambda x:x-1,map(int,raw_input().split()))
l.sort()
if not l in qs:
qs.append(l)
remain -= 1
MIN = 1000000000
MAX = -1
tt = []
for i in qs:
tt += i
t = 0
for j in i:
t+=a[j]
MIN = min(MIN,float(t)/ll)
MAX = max(MAX,float(t)/ll)
for i in sorted(list(set(tt)),reverse=True):
del a[i]
if(remain != 0):
a.sort()
t = float(sum(a[:ll]))/ll
MIN = min(MIN,t)
MAX = max(MAX,t)
a.sort(reverse=True)
t = float(sum(a[:ll]))/ll
MIN = min(MIN,t)
MAX = max(MAX,t)
sys.stdout.write("%.9f %.9f" %(MIN,MAX))
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment