Skip to content

Instantly share code, notes, and snippets.

@haje01
Created Nov 24, 2014
Embed
What would you like to do?
손고리즘 - Festival
def calc_mavg(prc, ft):
mavg = 100
n = len(prc)
fs = 0
for start in xrange(0, n - ft + 1):
cur = start + ft
fs = sum(prc[start:cur]) if fs == 0 else fs - prc[start - 1] + prc[cur - 1]
avg = fs / float(cur - start)
if avg < mavg:
mavg = avg
s = fs
while cur < n:
s += prc[cur]
cur += 1
avg = s / float(cur - start)
if avg < mavg:
mavg = avg
return mavg
if __name__ == "__main__":
c = int(raw_input())
for i in xrange(c):
_, l = [int(i) for i in raw_input().strip().split()]
prc = [int(i) for i in raw_input().strip().split()]
print "%.11f" % calc_mavg(prc, l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment