Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 12:11:30
Task:Cent saving
Sender:Verto
Submission time:2016-05-28 12:11:30
Status:READY
Result:ACCEPTED

Show test data

Code

import sys
def asints(s):
	return [int(x.strip()) for x in s.split()]
def asoneint(s):
	return int(s.strip())
lines = sys.stdin.readlines()

t = asoneint(lines[0])
for i in range(t):
	n = asoneint(lines[1+i*2])
	ps = asints(lines[2+i*2])
	price = 0
	rem3 = 0
	rem4 = 0
	for j in ps:
		a = j % 5
		b = (j // 5) * 5
		price += b
		if a == 3:
			rem3 += 1
		elif a == 4:
			rem4 += 1
	m = min(rem3, rem4)
	price += m * 5
	rem3 -= m
	rem4 -= m
	price += (rem3 // 2) * 5
	if rem3 % 2 == 1:
		price += 5
	price += (rem4 // 3) * 10
	rem4 = rem4 % 3
	price += rem4 * 5
	print price