結果

提出番号 572
提出者 uwi
言語 Python3
提出日時 2017-07-25 23:29:12
問題名 (18)おまんじゅうわけわけ
結果 AC
点数 100%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 35ms 31056KB
2 AC 100% 67ms 31104KB
3 AC 100% 36ms 31168KB
4 AC 100% 173ms 69184KB
5 AC 100% 179ms 68272KB
6 AC 100% 131ms 68688KB
7 AC 100% 203ms 68352KB
8 AC 100% 179ms 68512KB
9 AC 100% 168ms 70144KB

ソースコード

n = int(input())
a = list(map(int, input().split()))

tot = sum(a)
f = [[],[],[]]
for v in a:
	f[v%3].append(v)
f[0].sort()
f[1].sort()
f[2].sort()

if tot % 3 == 0:
	print(tot)
elif tot % 3 == 1:
	ans = 0
	if len(f[1]) >= 1:
		ans = max(ans, tot - f[1][0])
	if len(f[2]) >= 2:
		ans = max(ans, tot - f[2][0] - f[2][1])
	if ans == 0:
		print(-1)
	else:
		print(ans)
else:
	ans = 0
	if len(f[2]) >= 1:
		ans = max(ans, tot - f[2][0])
	if len(f[1]) >= 2:
		ans = max(ans, tot - f[1][0] - f[1][1])
	if ans == 0:
		print(-1)
	else:
		print(ans)