N=int(input())
a=[]
sum = 0
f = 0
c = 0
for i in range(N):
l = int(input())
sum = sum + l
a.append(l)
if N == 1:
print(1)
else:
ans = []
for i in range(N-1, 0, -1):
if a[i] > a[i-1]:
if sum > a[-1] or (sum > a[i+1] and f == 1):
for k in range(c+1):
ans.append(1)
f = 1
ans.append(0)
elif a[i] == a[i-1]:
c += 1
sum=sum-a[i]
ans = ans[::-1]
print(0)
for i in range(c):
for i in ans:
print(i)
Объяснение:
с тебя 500 рублей у меня сегодня др
N = int(input())
exit(0)
bacteria = [0] * N
for i in range(0, N):
bacteria[i] = int(input())
prefix_sum = [bacteria[0]] * N
for i in range(1, N):
prefix_sum[i] = prefix_sum[i - 1] + bacteria[i]
ans = [0] * N
if bacteria[N-1] > bacteria[0]:
ans[N - 1] = 1
for i in reversed(range(2, N)):
if ans[i] == 1:
prev = i - 1
if prefix_sum[prev] > bacteria[i] and bacteria[0] < bacteria[prev]:
ans[prev] = 1
print(ans[i])
g++-GNU C++ 8.3.1
N=int(input())
a=[]
sum = 0
f = 0
c = 0
for i in range(N):
l = int(input())
sum = sum + l
a.append(l)
if N == 1:
print(1)
else:
ans = []
for i in range(N-1, 0, -1):
if a[i] > a[i-1]:
if sum > a[-1] or (sum > a[i+1] and f == 1):
for k in range(c+1):
ans.append(1)
c = 0
f = 1
else:
ans.append(0)
f = 0
elif a[i] == a[i-1]:
c += 1
else:
ans.append(0)
f = 0
sum=sum-a[i]
ans = ans[::-1]
print(0)
for i in range(c):
print(0)
for i in ans:
print(i)
Объяснение:
с тебя 500 рублей у меня сегодня др
N = int(input())
if N == 1:
exit(0)
bacteria = [0] * N
for i in range(0, N):
bacteria[i] = int(input())
prefix_sum = [bacteria[0]] * N
for i in range(1, N):
prefix_sum[i] = prefix_sum[i - 1] + bacteria[i]
ans = [0] * N
if bacteria[N-1] > bacteria[0]:
ans[N - 1] = 1
for i in reversed(range(2, N)):
if ans[i] == 1:
prev = i - 1
if prefix_sum[prev] > bacteria[i] and bacteria[0] < bacteria[prev]:
ans[prev] = 1
for i in range(N):
print(ans[i])
Объяснение:
g++-GNU C++ 8.3.1