aacord’s memo

abcを中心にpythonで解いた問題のメモ、整理をしています。緑になった。

076 - Cake Cut(★3)

尺取り法のめも

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
s = sum(a)/10
a += a

now = [0,0]
f = False
for i in a:
  if now[0] < s:
    now[0] += i
  elif now[0] == s:
    f = True
    break
  else:
    v = now[1]
    for j in range(v,2*n):
      now[0] -= a[j]
      now[1] += 1
      if now[0] == s:
        f = True
        break
      elif now[0] < s:
        break
    now[0] += i
    
  #print(now)
  
if f:
  print('Yes')
else:
  print('No')