瀏覽代碼

2020/9

master
Roderic Day 4 年之前
父節點
當前提交
cd6a007d7b
共有 1 個文件被更改,包括 22 次插入0 次删除
  1. +22
    -0
      y2020/p09.py

+ 22
- 0
y2020/p09.py 查看文件

@@ -0,0 +1,22 @@
import sys
from itertools import combinations


text = sys.stdin.read()
ns = [int(n) for n in text.splitlines()]
for i, n in enumerate(ns):
if i >= 25 and n not in {a + b for a, b in combinations(ns[:i][-25:], 2)}:
ans1 = n
print(ans1)


i, j, s = 0, 0, ns[0]
while s != ans1:
if s < ans1:
j += 1
s += ns[j]
elif s > ans1:
s -= ns[i]
i += 1
ans2 = min(ns[i:j]) + max(ns[i:j])
print(ans2)

Loading…
取消
儲存