Problem:


Score : 700 points

Problem Statement

You have an integer sequence of length N: a_1, a_2, ..., a_N.

You repeatedly perform the following operation until the length of the sequence becomes 1:

First, choose an element of the sequence.

If that element is at either end of the sequence, delete the element.

If that element is not at either end of the sequence, replace the element with the sum of the two elements that are adjacent to it. Then, delete those two elements.

You would like to maximize the final element that remains in the sequence.

Find the maximum possible value of the final element, and the way to achieve it.

Constraints

All input values are integers.

2 \leq N \leq 1000

|a_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

In the first line, print the maximum possible value of the final element in the sequence.

In the second line, print the number of operations that you perform.

In the (2+i)-th line, if the element chosen in the i-th operation is the x-th element from the left in the sequence at that moment, print x.

If there are multiple ways to achieve the maximum value of the final element, any of them may be printed.

Sample Input 1

5
1 4 3 7 5

Sample Output 1

11
3
1
4
2

The sequence would change as follows:

After the first operation: 4, 3, 7, 5

After the second operation: 4, 3, 7

After the third operation: 11(4+7)

Sample Input 2

4
100 100 -1 100

Sample Output 2

200
2
3
1

After the first operation: 100, 200(100+100)

After the second operation: 200

Sample Input 3

6
-1 -2 -3 1 2 3

Sample Output 3

4
3
2
1
2

After the first operation: -4, 1, 2, 3

After the second operation: 1, 2, 3

After the third operation: 4

Sample Input 4

9
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 4

5000000000
4
2
2
2
2



Sample input:
5
1 4 3 7 5


Sample output:
11
3
1
4
2

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans1 = sum([a[i] for i in range(0, n, 2) if a[i] > 0])
ans2 = sum([a[i] for i in range(1, n, 2) if a[i] > 0])
if max(ans1, ans2) == 0:
	print(0)
	print(n-1)
	for _ in range(n-1):
		print(1)

elif ans1 >= ans2:
	print(ans1)
	op = []
	left = 0
	while a[left] <= 0:
		left += 2

	right = True
	in_seg = False
	for i in range(n-1, -1, -1):
		if right:
			if i%2 == 1 or a[i] <= 0:
				op.append(i+1)
			else:
				right = False
		elif i < left:
			op += [1] * (i+1)
			break
		else:
			if in_seg == False and i%2 == 1:
				in_seg = True
				seg_right = i
			elif i%2 == 0 and a[i] > 0:
				in_seg = False
				op += list(range((i+seg_right+3)//2, i+1, -1))

	print(len(op))
	print(*op, sep="\n")

else:
	print(ans2)
	op = []
	left = 1
	while a[left] <= 0:
		left += 2

	right = True
	in_seg = False
	for i in range(n-1, -1, -1):
		if right:
			if i%2 == 0 or a[i] <= 0:
				op.append(i+1)
			else:
				right = False
		elif i < left:
			op += [1] * (i+1)
			break
		else:
			if in_seg == False and i%2 == 0:
				in_seg = True
				seg_right = i
			elif i%2 == 1 and a[i] > 0:
				in_seg = False
				op += list(range((i+seg_right+3)//2, i+1, -1))

	print(len(op))
	print(*op, sep="\n")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans1 = sum([a[i] for i in range(0, n, 2) if a[i] > 0])
ans2 = sum([a[i] for i in range(1, n, 2) if a[i] > 0])
if max(ans1, ans2) == 0:
	print(0)
	print(n)
	for _ in range(n):
		print(1)

elif ans1 >= ans2:
	print(ans1)
	op = []
	left = 0
	while a[left] <= 0:
		left += 2

	right = True
	in_seg = False
	for i in range(n-1, -1, -1):
		if right:
			if i%2 == 1 or a[i] <= 0:
				op.append(i+1)
			else:
				right = False
		elif i < left:
			op += [1] * (i+1)
			break
		else:
			if in_seg == False and i%2 == 1:
				in_seg = True
				seg_right = i
			elif i%2 == 0 and a[i] > 0:
				in_seg = False
				op += list(range((i+seg_right+3)//2, i+1, -1))

	print(len(op))
	print(*op, sep="\n")

else:
	print(ans2)
	op = []
	left = 1
	while a[left] <= 0:
		left += 2

	right = True
	in_seg = False
	for i in range(n-1, -1, -1):
		if right:
			if i%2 == 0 or a[i] <= 0:
				op.append(i+1)
			else:
				right = False
		elif i < left:
			op += [1] * (i+1)
			break
		else:
			if in_seg == False and i%2 == 0:
				in_seg = True
				seg_right = i
			elif i%2 == 1 and a[i] > 0:
				in_seg = False
				op += list(range((i+seg_right+3)//2, i+1, -1))

	print(len(op))
	print(*op, sep="\n")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans1 = sum([a[i] for i in range(0, n, 2) if a[i] > 0])
ans2 = sum([a[i] for i in range(1, n, 2) if a[i] > 0])
if max(ans1, ans2) == 0:
	print(0)
	print(n)
	print(*list(range(n, 0, -1)), sep="\n")

elif ans1 >= ans2:
	print(ans1)
	op = []
	left = 0
	while a[left] <= 0:
		left += 2

	right = True
	in_seg = False
	for i in range(n-1, -1, -1):
		if right:
			if i%2 == 1 or a[i] <= 0:
				op.append(i+1)
			else:
				right = False
		elif i < left:
			op += [1] * (i+1)
			break
		else:
			if in_seg == False and i%2 == 1:
				in_seg = True
				seg_right = i
			elif i%2 == 0 and a[i] > 0:
				in_seg = False
				op += list(range((i+seg_right+3)//2, i+1, -1))

	print(len(op))
	print(*op, sep="\n")

else:
	print(ans2)
	op = []
	left = 1
	while a[left] <= 0:
		left += 2

	right = True
	in_seg = False
	for i in range(n-1, -1, -1):
		if right:
			if i%2 == 0 or a[i] <= 0:
				op.append(i+1)
			else:
				right = False
		elif i < left:
			op += [1] * (i+1)
			break
		else:
			if in_seg == False and i%2 == 0:
				in_seg = True
				seg_right = i
			elif i%2 == 1 and a[i] > 0:
				in_seg = False
				op += list(range((i+seg_right+3)//2, i+1, -1))

	print(len(op))
	print(*op, sep="\n")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans1 = sum([a[i] for i in range(0, n, 2) if a[i] > 0])
ans2 = sum([a[i] for i in range(1, n, 2) if a[i] > 0])
if max(ans1, ans2) == 0:
	print(0)
	print(n)
	print(*list(range(n, 0, -1)), sep="\n")

elif ans1 >= ans2:
	print(ans1)
	op = []
	left = 0
	while a[left] <= 0:
		left += 2

	right = True
	in_seg = False
	for i in range(n-1, -1, -1):
		if right:
			if i%2 == 1 or a[i] <= 0:
				op.append(i+1)
			else:
				right = False
		elif i < left:
			op.append(i+1)
		else:
			if in_seg == False and i%2 == 1:
				in_seg = True
				seg_right = i
			elif i%2 == 0 and a[i] > 0:
				in_seg = False
				op += list(range((i+seg_right+3)//2, i+1, -1))

	print(len(op))
	print(*op, sep="\n")

else:
	print(ans2)
	op = []
	left = 1
	while a[left] <= 0:
		left += 2

	right = True
	in_seg = False
	for i in range(n-1, -1, -1):
		if right:
			if i%2 == 0 or a[i] <= 0:
				op.append(i+1)
			else:
				right = False
		elif i < left:
			op.append(i+1)
		else:
			if in_seg == False and i%2 == 0:
				in_seg = True
				seg_right = i
			elif i%2 == 1 and a[i] > 0:
				in_seg = False
				op += list(range((i+seg_right+3)//2, i+1, -1))

	print(len(op))
	print(*op, sep="\n")

Submission status: Wrong Answer

Solution code:
N = int(input())
A_ = list(map(int, input().split()))
ma = -float("inf")
ama = -1
for i, a in enumerate(A_):
    if a>=0:
        break
    if ma < a:
        ma = a
        ama = i
else:
    print(ma)
    print(N-1)
    Ans = []
    for i in range(N, ama+1, -1):
        Ans.append(i)
    for i in range(ama):
        Ans.append(1)
    print("\n".join(map(str, Ans)))
    exit()

A = A_[:]

R1 = []
an1 = 0
for i in range(0, N, 2):
    a = A[i]
    if a>=0:
        an1 += a
    else:
        R1.append(i)
idx_r1 = i
R2 = []
an2 = 0
for i in range(1, N, 2):
    a = A[i]
    if a>=0:
        an2 += a
    else:
        R2.append(i)
idx_r2 = i
ans, R, idx_r = (an1, R1, idx_r1) if an1 > an2 else (an2, R2, idx_r2)
idx_r += 1
print(ans)
Ans = []

for idx in R[::-1]:
    del A[idx]
    if 1<=idx<len(A):
        A[idx-1] += A.pop(idx)
    Ans.append(idx+1)
for idx in range(idx_r, -1, -2):
    if 0<=idx<len(A):
        del A[idx]
        if 1<=idx<len(A):
            A[idx-1] += A.pop(idx)
        Ans.append(idx+1)
print(len(Ans))
print("\n".join(map(str, Ans)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A_ = list(map(int, input().split()))
Ans1 = []
A = A_[:]

R1 = []
an1 = 0
for i in range(0, N, 2):
    a = A[i]
    if a>=0:
        an1 += a
    else:
        R1.append(i)
idx_r1 = i
R2 = []
an2 = 0
for i in range(1, N, 2):
    a = A[i]
    if a>=0:
        an2 += a
    else:
        R2.append(i)
idx_r2 = i
ans, R, idx_r = (an1, R1, idx_r1) if an1 > an2 else (an2, R2, idx_r2)
idx_r += 1
print(ans)
Ans = []

for idx in R[::-1]:
    del A[idx]
    if 1<=idx<len(A):
        A[idx-1] += A.pop(idx)
    Ans.append(idx+1)
for idx in range(idx_r, -1, -2):
    if 0<=idx<len(A):
        del A[idx]
        if 1<=idx<len(A):
            A[idx-1] += A.pop(idx)
        Ans.append(idx+1)
print(len(Ans))
print("\n".join(map(str, Ans)))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

# 奇数番目、または偶数番目、の好きな部分集合を足せる（ただし1元以上）
# 交互に塗り分けると交互が維持されることから分かる

N = int(input())
A = np.array(input().split(), dtype=np.int64)

def select_operation(select,N):
    result = []
    # 余分な左端
    x = select.min()
    result = [0] * x
    select -= x
    N -= x
    # 余分な右端
    y = select.max()
    result += [y + 1] * (N - y - 1)
    N = y + 1
    # 右から見て、要らない偶数を除外
    result += np.setdiff1d(np.arange(N)[::2], select)[::-1].tolist()
    # 0,2,4,...番目を集約
    result += [1] * (len(select) - 1)
    result = [1+x for x in result]
    return result

ev_sum = np.maximum(0,A[::2]).sum()
od_sum = np.maximum(0,A[1::2]).sum()
if ev_sum >= od_sum > 0:
    select = np.where(A[::2] >= 0)[0] * 2
elif od_sum > 0:
    select = np.where(A[1::2] >= 0)[0] * 2 + 1
else:
    n = np.argmax(A)
    select = np.array([n])
S = A[select].sum()

ope = select_operation(select,N)

# 答えの出力
print(S)
print(len(ope))
print('\n'.join(map(str,ope)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
g1 = [0]+a[1::2]
g2 = [0]+a[::2]
for i in range(1,len(g1)):
    g1[i] += g1[i-1]
for i in range(1,len(g2)):
    g2[i] += g2[i-1]
s1 = [0,0,g1[0]]
s2 = [0,0,g2[0]]
for i in range(len(g1)-1):
    for j in range(i+1,len(g1)):
        if g1[j]-g1[i]>s1[2]:
            s1 = [i,j,g1[j]-g1[i]]
for i in range(len(g2)-1):
    for j in range(i+1,len(g2)):
        if g2[j]-g2[i]>s2[2]:
            s2 = [i,j,g2[j]-g2[i]]
if s1[2]>=s2[2]:
    print(s1[2])
    ans = []
    for i in range(n,s1[1]*2,-1):
        ans.append(i)
    for i in range(2*s1[0]+1):
        ans.append(1)
    for i in range(s1[1]-s1[0]-1):
        ans.append(2)
    print(len(ans))
    for a in ans:
        print(a)
else:
    print(s2[2])
    ans = []
    for i in range(n,s2[1]*2-1,-1):
        ans.append(i)
    for i in range(2*s2[0]):
        ans.append(1)
    for i in range(s2[1]-s2[0]-1):
        ans.append(2)
    print(len(ans))
    for a in ans:
        print(a)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3


def solve(n, aa):

    sum0 = 0
    sum1 = 0
    for i in range(n):
        a = aa[i]
        if 0 < a:
            if i % 2 == 0:
                sum0 += a
            else:
                sum1 += a

    used = [False] * n
    i0 = 1 if sum0 < sum1 else 0
    for i in range(i0, n, 2):
        if 0 < aa[i]:
            used[i] = True

    opa = []
    k = n
    for i in range(n - 1, -1, -1):
        if not used[i]:
            opa.append(i + 1)
            k -= 1
        else:
            break
    j = 0
    for i in range(k):
        if not used[i]:
            opa.append(1)
            j += 1
        else:
            break

    c = 0
    for i in range(k - 1, j - 1, -1):
        if used[i]:
            c = 0
        else:
            c += 1
            if c == 3:
                opa.append(i - j + 2)
                k -= 2
                c = 1


    for i in range((k - j) // 2):
        opa.append(2)

    print(max(sum0, sum1))
    print(len(opa))
    for v in opa:
        print(v)


def main():
    n = input()
    n = int(n)
    aa = list(map(int, input().split()))

    solve(n, aa)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
N=int(input())
As=[int(i) for i in input().split()]
neg_odd,neg_even=deque([]),deque([])
S_odd,S_even=0,0
for i,A in enumerate(As):
  if i%2==0:
    if A>=0:
      S_even+=A
    else:
      neg_even.append(i)
  if i%2==1:
    if A>=0:
      S_odd+=A
    else:
      neg_odd.append(i)
ans=[]
A_size=N
if S_odd==S_even==0:
  a=max(As)
  print(a)
  i=0
  while As[i]!=a:
    ans.append(1)
    i+=1
    A_size-=1
  while A_size>1:
    ans.append(A_size)
    A_size-=1
elif S_odd<=S_even:
  print(S_even)
  if N%2==0:
    ans.append(N)
    A_size-=1
  if neg_even:
    t=0
    while A_size-1==neg_even[-1]:
      neg_even.pop()
      ans.append(A_size)
      ans.append(A_size-1)
      A_size-=2
      if not neg_even:
        break
    if neg_even:
      while t==neg_even[0]:
        neg_even.popleft()
        ans.append(1)
        ans.append(1)
        t+=2
        A_size-=2
        if not neg_even:
          break
    for a in neg_even:
      ans.append(a+1-t)
      A_size-=2
      t+=2
  while A_size>1:
    ans.append(2)
    A_size-=2
else:
  print(S_odd)
  if N%2==1:
    ans.append(N)
    A_size-=1
  ans.append(1)
  A_size-=1
  if neg_odd:
    t=1
    while A_size==neg_odd[-1]:
      neg_odd.pop()
      ans.append(A_size)
      ans.append(A_size-1)
      A_size-=2
      if not neg_odd:
        break
    if neg_odd:
      while t==neg_odd[0]:
        neg_odd.popleft()
        ans.append(1)
        ans.append(1)
        t+=2
        A_size-=2
        if not neg_odd:
          break
    for a in neg_odd:
      ans.append(a-t)
      A_size-=2
      t+=2
  while A_size>1:
    ans.append(2)
    A_size-=2
print(len(ans))
for a in ans:
  print(a)

Submission status: Wrong Answer

Solution code:
from collections import deque
N=int(input())
As=[int(i) for i in input().split()]
neg_odd,neg_even=deque([]),deque([])
S_odd,S_even=0,0
for i,A in enumerate(As):
  if i%2==0:
    if A>=0:
      S_even+=A
    else:
      neg_even.append(i)
  if i%2==1:
    if A>=0:
      S_odd+=A
    else:
      neg_odd.append(i)
ans=[]
A_size=N
if S_odd==S_even==0:
  a=max(As)
  print(a)
  i=0
  while As[i]!=a:
    ans.append(1)
    i+=1
    A_size-=1
  while A_size>1:
    ans.append(A_size)
    A_size-=1
elif S_odd<=S_even:
  print(S_even)
  if N%2==0:
    ans.append(N)
    A_size-=1
  if neg_even:
    t=0
    s=neg_even[0]
    while t==s:
      neg_even.popleft()
      ans.append(1)
      ans.append(1)
      t+=2
      A_size-=2
    for a in neg_even:
      ans.append(a+1-t)
      A_size-=2
      t+=2
  while A_size>1:
    ans.append(2)
    A_size-=2
else:
  print(S_odd)
  if N%2==1:
    ans.append(N)
    A_size-=1
  ans.append(1)
  A_size-=1
  if neg_odd:
    t=1
    s=neg_odd[0]
    while t==s:
      neg_odd.popleft()
      ans.append(1)
      ans.append(1)
      t+=2
      A_size-=2
    for a in neg_odd:
      ans.append(a-t)
      A_size-=2
      t+=2
  while A_size>1:
    ans.append(2)
    A_size-=2
print(len(ans))
for a in ans:
  print(a)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
a = [(int(v),i) for i, v in enumerate(input().split())]
ao = sum([v for v, i in a if i%2 and v>0])
ae = sum([v for v, i in a if not i%2 and v>0])
if max(ao, ae)== 0:
    ai = a.index(max(a))
    Ans = [1]*(ai)+list(range(N-ai,1,-1))
    print(max(a))
    print(len(Ans))
    for i in Ans:
        print(i)
    sys.exit()
if ao >= ae:
    print(ao)
    yn = [i for v, i in a if i%2 and v>0]
else:
    print(ae)
    yn = [i for v, i in a if not i%2 and v>0]
listyn = [i in yn for i in range(N)]
Ans = []
while not listyn[0]:
    Ans.append(1)
    listyn = listyn[1:]
while not listyn[-1]:
    Ans.append(len(listyn))
    listyn = listyn[:-1]
while True:
    if len(listyn) == 1:
        break
    if len(listyn) == [2,3]:
        Ans.append(2)
        break
    if listyn[2]:
        Ans.append(2)
        listyn = [True] + listyn[3:]
    else:
        Ans.append(3)
        listyn = [True, False] + listyn[4:]
print(len(Ans))
for i in Ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
a = [(int(v),i) for i, v in enumerate(input().split())]
ao = sum([v for v, i in a if i%2 and v>0])
ae = sum([v for v, i in a if not i%2 and v>0])
if max(ao, ae)== 0:
    ai = a.index(max(a))
    Ans = [1]*(ai)+list(range(N-ai,1,-1))
    for i in Ans:
        print(i)
    sys.exit()
if ao >= ae:
    print(ao)
    yn = [i for v, i in a if i%2 and v>0]
else:
    print(ae)
    yn = [i for v, i in a if not i%2 and v>0]
listyn = [i in yn for i in range(N)]
Ans = []
while not listyn[0]:
    Ans.append(1)
    listyn = listyn[1:]
while not listyn[-1]:
    Ans.append(len(listyn))
    listyn = listyn[:-1]
while True:
    if len(listyn) == 1:
        break
    if len(listyn) == [2,3]:
        Ans.append(2)
        break
    if listyn[2]:
        Ans.append(2)
        listyn = [True] + listyn[3:]
    else:
        Ans.append(3)
        listyn = [True, False] + listyn[4:]
print(len(Ans))
for i in Ans:
    print(i)

Submission status: Wrong Answer

Solution code:
def inpl(): return [int(i) for i in input().split()]
import itertools, sys
N = int(input())
a = inpl()
if N == 1:
    print(a[0])
    print(0)
    sys.exit()
ao = [0]+list(itertools.accumulate([v for i, v in enumerate(a) if i%2]))
ae = [0]+list(itertools.accumulate([v for i, v in enumerate(a) if not i%2]))
ans = max(a)
ai, aj = [a.index(ans)]*2
if len(ae) > 1:
    for i,j in itertools.combinations(range(len(ae)),2):
        t = ae[j]-ae[i]
        if ans < t :
            ans = t
            ai, aj = 2*i, 2*j-2
if len(ao) > 1:
    for i,j in itertools.combinations(range(len(ao)),2):
        t = ao[j]-ao[i]
        if ans < t :
            ans = t
            ai, aj = 2*i+1, 2*j-1
print(ans)
if ai == aj:
    Ans = [1]*(ai)+list(range(N-ai,1,-1))
else:
    Ans = [1]*(ai) +list(range(N-ai,aj-ai+1,-1)) + [2]*((aj-ai)//2)
print(len(Ans))
for i in Ans:
    print(i)

Submission status: Wrong Answer

Solution code:

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

sum_1=0
sum_2=0
pos_list_1 = [0 for i in range(N)]
pos_list_2 = [0 for i in range(N)]


if max(a)<0:
    pos_list_1[a.index(max(a))]=1
    print(max(a))
    zero_start = -1
    ope_list = []
    for i in range(N):
        if pos_list_1[N-i-1]==0:
            if zero_start==-1:
                zero_start=N-i
        if pos_list_1[N-i-1]==1:
            if zero_start!=-1:
                for j in range(int((zero_start-(N-i+1))/2)+1):
                    ope_list.append(int((zero_start+N-i+1)/2)-j)
                zero_start=-1
    if zero_start!=-1:
        for j in range(int((zero_start+1)/2)):
            ope_list.append(int((zero_start+1)/2)-j)        
else:
    
    if N%2==0:
        for i in range(int(N/2)):
            if a[2*i]>=0:
                sum_1+=a[2*i]
                pos_list_1[2*i]=1
            if a[2*i+1]>=0:
                sum_2+=a[2*i+1]
                pos_list_2[2*i+1]=1
    else:
        for i in range(int(N/2)):
            if a[2*i]>=0:
                sum_1+=a[2*i]
                pos_list_1[2*i]=1
            if a[2*i+1]>=0:
                sum_2+=a[2*i+1]
                pos_list_2[2*i+1]=1
        if a[N-1]>=0:
            sum_1+=a[N-1]
            pos_list_1[N-1]=1
    
    if sum_1>=sum_2:
        print(sum_1)
        
        zero_start = -1
        ope_list = []
        for i in range(N):
            if pos_list_1[N-i-1]==0:
                if zero_start==-1:
                    zero_start=N-i
            if pos_list_1[N-i-1]==1:
                if zero_start!=-1:
                    for j in range(int((zero_start-(N-i+1))/2)+1):
                        ope_list.append(int((zero_start+N-i+1)/2)-j)
                    zero_start=-1
        if zero_start!=-1:
            for j in range(int((zero_start+1)/2)):
                ope_list.append(int((zero_start+1)/2)-j)        
    
    else:
        print(sum_2)
        zero_start = -1
        ope_list = []
    
        for i in range(N):
            if pos_list_2[N-i-1]==0:
                if zero_start==-1:
                    zero_start=N-i
            if pos_list_2[N-i-1]==1:
                if zero_start!=-1:
                    for j in range(int((zero_start-(N-i+1))/2)+1):
                        ope_list.append(int((zero_start+N-i+1)/2)-j)
                    zero_start=-1
        if zero_start!=-1:
            for j in range(int((zero_start+1)/2)):
                ope_list.append(int((zero_start+1)/2)-j)
    
print(len(ope_list))

for ope in ope_list:
    print(ope)

Submission status: Wrong Answer

Solution code:

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

sum_1=0
sum_2=0
pos_list_1 = [0 for i in range(N)]
pos_list_2 = [0 for i in range(N)]
if N%2==0:
    for i in range(int(N/2)):
        if a[2*i]>=0:
            sum_1+=a[2*i]
            pos_list_1[2*i]=1
        if a[2*i+1]>=0:
            sum_2+=a[2*i+1]
            pos_list_2[2*i+1]=1
else:
    for i in range(int(N/2)):
        if a[2*i]>=0:
            sum_1+=a[2*i]
            pos_list_1[2*i]=1
        if a[2*i+1]>=0:
            sum_2+=a[2*i+1]
            pos_list_2[2*i+1]=1
    if a[N-1]>=0:
        sum_1+=a[N-1]
        pos_list_1[N-1]=1

if sum_1>=sum_2:
    print(sum_1)
    
    zero_start = -1
    ope_list = []
    for i in range(N):
        if pos_list_1[N-i-1]==0:
            if zero_start==-1:
                zero_start=N-i
        if pos_list_1[N-i-1]==1:
            if zero_start!=-1:
                for j in range(int((zero_start-(N-i+1))/2)+1):
                    ope_list.append(int((zero_start+N-i+1)/2)-j)
                zero_start=-1
    if zero_start!=-1:
        for j in range(int((zero_start+1)/2)):
            ope_list.append(int((zero_start+1)/2)-j)        

else:
    print(sum_2)
    zero_start = -1
    ope_list = []

    for i in range(N):
        if pos_list_2[N-i-1]==0:
            if zero_start==-1:
                zero_start=N-i
        if pos_list_2[N-i-1]==1:
            if zero_start!=-1:
                for j in range(int((zero_start-(N-i+1))/2)+1):
                    ope_list.append(int((zero_start+N-i+1)/2)-j)
                zero_start=-1
    if zero_start!=-1:
        for j in range(int((zero_start+1)/2)):
            ope_list.append(int((zero_start+1)/2)-j)
    
print(len(ope_list))

for ope in ope_list:
    print(ope)

Submission status: Wrong Answer

Solution code:

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

sum_1=0
sum_2=0
pos_list_1 = [0 for i in range(N)]
pos_list_2 = [0 for i in range(N)]
if N%2==0:
    for i in range(int(N/2)):
        if a[2*i]>=0:
            sum_1+=a[2*i]
            pos_list_1[2*i]=1
        if a[2*i+1]>=0:
            sum_2+=a[2*i+1]
            pos_list_2[2*i+1]=1
else:
    for i in range(int(N/2)):
        if a[2*i]>=0:
            sum_1+=a[2*i]
            pos_list_1[2*i]=1
        if a[2*i+1]>=0:
            sum_2+=a[2*i+1]
            pos_list_2[2*i+1]=1
    if a[N-1]>=0:
        sum_1+=a[N-1]
        pos_list_1[N-1]=1

if sum_1>=sum_2:
    print(sum_1)
    
    zero_start = -1
    ope_list = []
    for i in range(N):
        if pos_list_1[N-i-1]==0:
            if zero_start==-1:
                zero_start=N-i
        if pos_list_1[N-i-1]==1:
            if zero_start!=-1:
                for j in range(int((zero_start-(N-i+1))/2)+1):
                    ope_list.append(int((zero_start+N-i+1)/2)+j)
                zero_start=-1
    if zero_start!=-1:
        for j in range(int((zero_start+1)/2)):
            ope_list.append(int((zero_start+1)/2)-j)        

else:
    print(sum_2)
    zero_start = -1
    ope_list = []

    index_list=[i+1 for i in range(N)]
    for i in range(N):
        if pos_list_2[N-i-1]==0:
            if zero_start==-1:
                zero_start=N-i
        if pos_list_2[N-i-1]==1:
            if zero_start!=-1:
                for j in range(int((zero_start-(N-i+1))/2)+1):
                    ope_list.append(int((zero_start+N-i+1)/2)+j)
                zero_start=-1
    if zero_start!=-1:
        for j in range(int((zero_start+1)/2)):
            ope_list.append(int((zero_start+1)/2)-j)
    
print(len(ope_list))

for ope in ope_list:
    print(ope)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))

sum_1=0
sum_2=0
pos_list_1 = [0 for i in range(N)]
pos_list_2 = [0 for i in range(N)]
if N%2==0:
    for i in range(int(N/2)):
        if a[2*i]>=0:
            sum_1+=a[2*i]
            pos_list_1[2*i]=1
        if a[2*i+1]>=0:
            sum_2+=a[2*i+1]
            pos_list_2[2*i+1]=1
else:
    for i in range(int(N/2)):
        if a[2*i]>=0:
            sum_1+=a[2*i]
            pos_list_1[2*i]=1
        if a[2*i+1]>=0:
            sum_2+=a[2*i+1]
            pos_list_2[2*i+1]=1
    if a[N-1]>=0:
        sum_1+=a[N-1]
        pos_list_1[N-1]=1

if sum_1>=sum_2:
    print(sum_1)
    print(N-sum(pos_list_1))
    for i in range(N):
        if pos_list_1[N-i-1]==0:
            print(N-i)
else:
    print(sum_2)
    print(N-sum(pos_list_2))
    for i in range(N):
        if pos_list_2[N-i-1]==0:
            print(N-i)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = []
while len(a) != 1:
  MAX = max(a)
  basyo = -1
  for i in range(len(a)-2):
    if MAX <= a[i] + a[i+2]:
      basyo = i+1
      MAX = a[i] + a[i+2]
  if basyo == -1:
    print(max(a))
    ima = a.index(max(a))
    for i in range(len(a),ima+1,-1):
      ans.append(i)
    ans.extend([1]*ima)
    print(len(ans))
    for i in ans:
      print(i)
    exit()
  a[basyo] = a[basyo-1] + a[basyo+1]
  try:
    a[basyo-2] = -1
  except:
    pass
  try:
    a[basyo+2] = -1
  except:
    pass
  a.pop(basyo+1)
  a.pop(basyo-1)
  ans.append(basyo+1)
print(a[0])
print(len(ans))
for i in ans:
  print(i)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b

def check(A, operations):
    for o in operations:
        if o == 1:
            A = A[1:]
        elif o == len(A):
            A = A[:len(A) - 1]
        else:
            o -= 1
            A = A[:o - 1] + [A[o - 1] + A[o + 1]] + A[o + 2:]

    print(A)
    assert(len(A) == 1)
    return A[0]

def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans1 = 0
    del1 = []
    ok1 = False
    for i in range(0, N, 2):
        if A[i] >= 0:
            ans1 += A[i]
            ok1 = True
        else:
            del1.append(i + 1)

    ans2 = 0
    del2 = [1]
    ok2 = False
    for i in range(1, N, 2):
        if A[i] >= 0:
            ans2 += A[i]
            ok2 = True
        else:
            del2.append(i + 1)

    del1 = del1[::-1]
    del2 = del2[::-1]

    ans, dele = None, None
    if ok1 and ok2:
        if ans1 > ans2:
            ans, dele = ans1, del1
        else:
            ans, dele = ans2, del2
    elif ok1:
        ans, dele = ans1, del1
    elif ok2:
        ans, dele = ans2, del2

    if not ok1 and not ok2:
        ans = max(A)
        idx = A.index(ans)
        print(ans)
        a = []
        for i in range(N, 0, -1):
            if i != idx + 1:
                a.append(i)
        print(len(a))
        print(*a, sep="\n")

    else:
        print(ans)
        e = int(1 in dele) + int(N in dele)
        for i in range((N - (len(dele) - e) * 2 - e) // 2):
            dele.append(2)
        print(len(dele))
        print(*dele, sep="\n")

        # print(check(A, dele))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N = input()
a = map(int, raw_input().split())
S1 = S2 = 0
for i in range(N):
    if i % 2:
        if a[i] > 0:
            S1 += a[i]
    else:
        if a[i] > 0:
            S2 += a[i]
if S1 == S2 == 0:
    print max(a)
    maxm = -INF
    for i in range(N):
        if maxm < a[i]:
            maxm = a[i]
            pos = i
    a[pos] = 1
    if pos % 2:
        S1 = 1
    else:
        S2 = 1
else:
    print max(S1, S2)
ls = []
while True:
    flag = True
    for i in range(S1 > S2, len(a), 2):
        if a[i] < 0:
            ls.append(i + 1)
            if i == 0:
                a = a[1:]
            elif i == len(a) - 1:
                a = a[:-1]
            else:
                S = a[i - 1] + a[i + 1]
                a = a[:i - 1] + [S] + a[i + 2:]
            flag = False
            break
    if flag:
        break
for i in range(len(a)):
    a[i] = (i % 2 == (S1 > S2))
while True:
    flag = True
    for i in range(len(a)):
        if not a[i]:
            ls.append(i + 1)
            if i == 0:
                a = a[1:]
            elif i == len(a) - 1:
                a = a[:-1]
            else:
                a = a[:i - 1] + [True] + a[i + 2:]
            flag = False
            break
    if flag:
        break

print len(ls)
for num in ls:
    print num

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N = input()
a = map(int, raw_input().split())
S1 = S2 = 0
for i in range(N):
    if i % 2:
        if a[i] > 0:
            S1 += a[i]
    else:
        if a[i] > 0:
            S2 += a[i]

print max(S1, S2)
ls = []
while True:
    flag = True
    for i in range(S1 > S2, len(a), 2):
        if a[i] < 0:
            ls.append(i + 1)
            if i == 0:
                a = a[1:]
            elif i == len(a) - 1:
                a = a[:-1]
            else:
                S = a[i - 1] + a[i + 1]
                a = a[:i - 1] + [S] + a[i + 2:]
            flag = False
            break
    if flag:
        break
for i in range(len(a)):
    a[i] = (i % 2 == (S1 > S2))
while True:
    flag = True
    for i in range(len(a)):
        if not a[i]:
            ls.append(i + 1)
            if i == 0:
                a = a[1:]
            elif i == len(a) - 1:
                a = a[:-1]
            else:
                a = a[:i - 1] + [True] + a[i + 2:]
            flag = False
            break
    if flag:
        break

print len(ls)
for num in ls:
    print num