Problem:


Score : 100 points

Problem Statement

Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.

The vacation consists of N days.
For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:

A: Swim in the sea. Gain a_i points of happiness.

B: Catch bugs in the mountains. Gain b_i points of happiness.

C: Do homework at home. Gain c_i points of happiness.

As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.

Find the maximum possible total points of happiness that Taro gains.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq a_i, b_i, c_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N

Output

Print the maximum possible total points of happiness that Taro gains.

Sample Input 1

3
10 40 70
20 50 80
30 60 90

Sample Output 1

210

If Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210 points of happiness.

Sample Input 2

1
100 10 1

Sample Output 2

100

Sample Input 3

7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1

Sample Output 3

46

Taro should do activities in the order C, A, B, A, C, B, A.



Sample input:
3
10 40 70
20 50 80
30 60 90


Sample output:
210

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
x = []
y = []
z = []
for i in range(N):
    x1, y1, z1 = [int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    z.append(z1)

dp = np.array([0] * N)


for i in range(N):
    if i == 0:
        dp[i] = max(x[i], y[i], z[i])
    else:
        if dp[i - 1] != max(x[i-1], y[i-1], z[i-1]):
            dp[i] = max(x[i], y[i], z[i])
        else:
            a = []
            a.append(x[i])
            a.append(y[i])
            a.append(z[i])
            a.sort()
            dp[i] = a[1]


print(sum(dp))

Submission status: Wrong Answer

Solution code:
N = int(input())
H = []
for _ in range(N):
    H.append(list(map(int, input().split())))
dp = [[0, 0, 0] for _ in range(N)]
dp[0] = H[0]
for i,h in enumerate(H[1:], start=1):
    for k in range(3):
        dp[i][k] = h[k]+max(map(lambda x: x if dp[i-1].index(x)!=k else 0, dp[i-1]))
print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
M = []
for _ in range(N):
    M.append(list(map(int, input().split())))
h = [0]*N
c = 0
for i,m in enumerate(M):
    if i==0:
        h[i] = max(m)
        c = m.index(h[i])
    else:
        m[c] = 0
        h[i] = h[i-1]+max(m)
        c = m.index(h[i]-h[i-1])
print(h[-1])

Submission status: Wrong Answer

Solution code:
INF = float("inf")

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,input_func:[input_func() for _ in range(n)]

import importlib
import_module = lambda module_name:importlib.import_module(module_name)

init_array_1dim = lambda value,n:[value]*n # 1次元配列を生成
init_array_2dim = lambda value,n,m:[init_array_1dim(value,n) for _ in range(m)] # 2次元配列を生成

gcd_base = lambda value1,value2:import_module('fractions').gcd(value1,value2) # 最大公約数（2値)
gcd = lambda lst:import_module('functools').reduce(gcd_base,lst) # 最大公約数（リスト）
lcm_base = lambda value1,value2:(value1*value2)//gcd_base(value1,value2) # 最小公倍数(2値)
lcm = lambda lst:import_module('functools').reduce(lcm_base,lst,1) # 最小公倍数(リスト)

permutations = lambda lst,n:import_module('itertools').permutations(lst,n) # 順列
combinations = lambda lst,n:import_module('itertools').combinations(lst,n) # 組み合わせ
product = lambda lst1,lst2:import_module('itertools').product(lst1,lst2) # 二つのリストの直積

round = lambda value:round(value) # 四捨五入
ceil = lambda value:import_module('math').ceil(value) # 切り上げ
floor = lambda value:import_module('math').floor(value) # 切り捨て

# キュー
init_q = lambda lst: import_module('collections').deque(lst)
q_pop = lambda q: q.popleft() # 先頭から取り出し
q_push = lambda q,value:q.appendleft(value) # 先頭に追加（値）
q_pushlist = lambda q,lst:q.extendleft(lst) # 先頭に追加（リスト）
q_append = lambda q,value:q.append(value) # 末尾に追加（値）
q_appendlist = lambda q,lst:q.extend(lst) # 末尾に追加（リスト）

# プライオリティキュー
init_heap = lambda a:import_module('heapq').heapify(a)
heap_push = lambda a,v:import_module('heapq').heappush(a,v)
heap_pop = lambda a:import_module('heapq').heappop(a) # 最小値を取り出す

def solution():
    # ここに実装
    N = input_int()
    abc = input_lines(N,input_ints_list)

    dp = init_array_2dim(-1,3,N)
    for i in range(N):
        if i == 0:
            dp[i][0] = abc[0][0]
            dp[i][1] = abc[0][1]
            dp[i][2] = abc[0][2]
        else:
            dp[i][0] = dp[i-1][0] + max(abc[i][1],abc[i][2])
            dp[i][1] = dp[i-1][1] + max(abc[i][0],abc[i][2])
            dp[i][2] = dp[i-1][2] + max(abc[i][0],abc[i][1])
    print(max(dp[N-1]))
    
if __name__ == '__main__':
    solution()

Submission status: Wrong Answer

Solution code:
n = int(input())
li = [list(map(int, input().split())) for i in range(n)] + [[0]*3]

dp = [[0 for i in range(3)] for j in range(n+1)]
for i in range(3):
    dp[0][i] = li[0][i]

for i in range(n):
    dp[i+1][0] = dp[i][0] + max(li[i+1][1], li[i+1][2])
    dp[i+1][1] = dp[i][1] + max(li[i+1][0], li[i+1][2])
    dp[i+1][2] = dp[i][2] + max(li[i+1][0], li[i+1][1])

print(max(dp[n-1][0], dp[n-1][1], dp[n-1][2]))

Submission status: Wrong Answer

Solution code:

N = int(input())

dp = [0]*N
abc = [list(map(int,input().split())) for i in range(N)]
yesterday = ''
if abc[0][1] < abc[0][0] and abc[0][2] < abc[0][0]:
    dp[0] = abc[0][0]
    yesterday = 'a'
elif abc[0][0] < abc[0][1] and abc[0][2] < abc[0][1]:
    dp[0] = abc[0][1]
    yesterday = 'b'
else:
    dp[0] = abc[0][2]
    yesterday = 'c'

for i in range(1,N):
    if 'a' in yesterday:
        if abc[i][1] < abc[i][2]:
            dp[i] = dp[i-1] + abc[i][2]
            yesterday = 'c'
        elif abc[i][2] < abc[i][1]:
            dp[i] = dp[i-1] + abc[i][1]
            yesterday = 'b'
        elif i != N-1:
            if abc[i+1][2] < abc[i+1][1]:
                dp[i] = dp[i-1] + abc[i][2]
                yesterday = 'c'
            else:
                dp[i] = dp[i-1] + abc[i][1]
                yesterday = 'b'
    elif 'b' in yesterday:
        if abc[i][0] < abc[i][2]:
            dp[i] = dp[i-1] + abc[i][2]
            yesterday = 'c'
        elif abc[i][2] < abc[i][0]:
            dp[i] = dp[i-1] + abc[i][0]
            yesterday = 'a'
        elif i != N-1:
            if abc[i+1][0] < abc[i+1][2]:
                dp[i] = dp[i-1] + abc[i][0]
                yesterday = 'a'
            else:
                dp[i] = dp[i-1] + abc[i][2]
                yesterday = 'c'
    else:
        if abc[i][1] < abc[i][0]:
            dp[i] = dp[i-1] + abc[i][0]
            yesterday = 'a'
        elif abc[i][0] < abc[i][1]:
            dp[i] = dp[i-1] + abc[i][1]
            yesterday = 'b'
        elif i != N-1:
            if abc[i+1][0] < abc[i+1][1]:
                dp[i] = dp[i-1] + abc[i][0]
                yesterday = 'a'
            else:
                dp[i] = dp[i-1] + abc[i][1]
                yesterday = 'b'

print(dp[N-1])

Submission status: Wrong Answer

Solution code:
#問題 C
N=int(input())
ha,hb,hc = map(int,input().split())
for i in range(1,N):
    a,b,c=map(int,input().split())
    ha = max(ha+b,ha+c)
    hb = max(hb+a,hb+c)
    hc = max(hc+b,hc+a)
print(max(max(ha,hb),hc))
#     x,y,z = map(int,input().split())
#     print(x,y,z)

Submission status: Wrong Answer

Solution code:
N=int(input())
C=[ list(map(int,input().split(' '))) for i in range(N)]
dp=[]
for i in range(N):
	if i==0:
		dp.append(C[0]) #[a0,b0,c0]
	else:
		dp.append([ dp[i-1][j]+max(C[i][(j+1)%3], C[i][(j+2)%3]) for j in range(3) ])

print(max(dp[N-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
DATA = [tuple(map(int,input().split())) for i in range(N)]


for idx,datum in enumerate(DATA):
  if idx == 0:
    prev = datum
  else:
    a,b,c = datum
    prev = prev[0]+max(b,c),prev[1]+max(a,c),prev[2]+max(a,b)
    
print(max(prev))

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
dp = [[0 for i in range(3)] for j in range(N)]

a, b, c = map(int,input().split())
dp[0][0] = a
dp[0][1] = b
dp[0][2] = c

if N ==1:
    print(max(a, b, c))
    sys.exit()

a, b, c = map(int,input().split())
case1 = a + dp[0][1] 
case2 = a + dp[0][2] 
case3 = b + dp[0][0] 
case4 = b + dp[0][2] 
case5 = c + dp[0][0] 
case6 = c + dp[0][1]

dp[1][0] = max(case1,case2)
dp[1][1] = max(case3,case4)
dp[1][2] = max(case4,case5)

if N ==2:
    print(max(dp[1][0], dp[1][1], dp[1][2]))
    sys.exit()

for i in range (2, N):
    a, b, c = map(int,input().split())
    case1 = a + dp[i-1][1]
    case2 = a + dp[i-1][2]
    case3 = b + dp[i-1][0]
    case4 = b + dp[i-1][2]
    case5 = c + dp[i-1][0]
    case6 = c + dp[i-1][1]
    
    dp[i][0] = max(case1,case2)
    dp[i][1] = max(case3,case4)
    dp[i][2] = max(case5,case6)
    
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))

Submission status: Wrong Answer

Solution code:
N = int(input())
Aij = []
for i in range(N):
    Aij.append([int(i) for i in input().split()])
dp = [0]*N
dp[0] = max(Aij[0])
sel = Aij[0].index(max(Aij[0]))

for i in range(1,N):
    # 遷移の様子
    if sel == 0:
        if dp[i-1]+Aij[i][1]<dp[i-1]+Aij[i][2]:
            dp[i] = dp[i-1]+Aij[i][2]
            sel = 2
        else:
            dp[i] = dp[i-1]+Aij[i][1]
            sel = 1
    elif sel == 1:
        if dp[i-1]+Aij[i][2]<dp[i-1]+Aij[i][0]:
            dp[i] = dp[i-1]+Aij[i][0]
            sel = 0
        else:
            dp[i] = dp[i-1]+Aij[i][2]
            sel = 2
    else:
        if dp[i-1]+Aij[i][0]<dp[i-1]+Aij[i][1]:
            dp[i] = dp[i-1]+Aij[i][1]
            sel = 1
        else:
            dp[i] = dp[i-1]+Aij[i][0]
            sel = 0
    
print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
Aij = []
for i in range(N):
    Aij.append([int(i) for i in input().split()])
dp = [0]*N
dp[0] = max(Aij[0])
sel = Aij[0].index(max(Aij[0]))

for i in range(1,N):
    if sel == 0:
        if dp[i-1]+Aij[i][1]<dp[i-1]+Aij[i][2]:
            dp[i] = dp[i-1]+Aij[i][2]
            sel = 2
        else:
            dp[i] = dp[i-1]+Aij[i][1]
            sel = 1
    elif sel == 1:
        if dp[i-1]+Aij[i][2]<dp[i-1]+Aij[i][0]:
            dp[i] = dp[i-1]+Aij[i][0]
            sel = 0
        else:
            dp[i] = dp[i-1]+Aij[i][2]
            sel = 2
    elif sel == 2:
        if dp[i-1]+Aij[i][0]<dp[i-1]+Aij[i][1]:
            dp[i] = dp[i-1]+Aij[i][1]
            sel = 1
        else:
            dp[i] = dp[i-1]+Aij[i][0]
            sel = 0
    
print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
Aij = []
for i in range(N):
    # Aij[i] = [int(i) for i in input().split()]
    Aij.append([int(i) for i in input().split()])
dp = [0]*N
dp[0] = max(Aij[0])
sel = Aij[0].index(max(Aij[0]))
for i in range(1,N):
    if sel == 0:
        if dp[i-1]+Aij[i][1]<dp[i-1]+Aij[i][2]:
            dp[i] = dp[i-1]+Aij[i][2]
            sel = 2
        else:
            dp[i] = dp[i-1]+Aij[i][1]
            sel = 1
    elif sel == 1:
        if dp[i-1]+Aij[i][2]<dp[i-1]+Aij[i][0]:
            dp[i] = dp[i-1]+Aij[i][0]
            sel = 0
        else:
            dp[i] = dp[i-1]+Aij[i][2]
            sel = 2
    elif sel == 2:
        if dp[i-1]+Aij[i][0]<dp[i-1]+Aij[i][1]:
            dp[i] = dp[i-1]+Aij[i][1]
            sel = 1
        else:
            dp[i] = dp[i-1]+Aij[i][0]
            sel = 0
    
print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
h = []
for i in range(N):
    h.append(list(map(int, input().split(" "))))

Submission status: Wrong Answer

Solution code:
N = int(input())
h = []
for i in range(N):
    h.append(list(map(int, input().split(" "))))

cost = h[-1]
today_cost = [0 for i in range(3)]

for day in range(N-2, -1, -1):
    today_cost[0] = h[day][0] + max(cost[1], cost[2])
    today_cost[1] = h[day][1] + max(cost[0], cost[2])
    today_cost[2] = h[day][2] + max(cost[0], cost[1])
    cost = today_cost

print(max(cost))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [0 for _ in range(N)]
b = [0 for _ in range(N)]
c = [0 for _ in range(N)]

for i in range(N):
    a[i], b[i], c[i] = map(int, input().split(" "))
happy = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
    if i == 0:
        happy[i][0] = a[i]
        happy[i][1] = b[i]
        happy[i][2] = c[i]
    else:
        happy[i][0] = max(happy[i-1][0]+max(b[i], c[i]), happy[i-1][1]+max(c[i], a[i]), happy[i-1][2]+max(a[i], b[i]))
print(max(happy[-1]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

def main():
    #N = 3
    #data = [list(map(int, x.split())) for x in
    #        ["10 40 70",
    #         "20 50 80",
    #         "30 60 90"]]
    import sys
    N = int(sys.stdin.readline()[:-1])
    data = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
    #
    dp = [[0, 0, 0]] * N
    dp[0] = data[0]
    for i in range(1, N):
        dp[i][0] = dp[i-1][0] + max(data[i][1:])
        dp[i][1] = dp[i-1][1] + max(data[i][0], data[i][2])
        dp[i][2] = dp[i-1][2] + max(data[i][:2])
    #print(dp)
    print(max(dp[N-1]))

main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[0]*3
for i in range(n):
    dp[0],dp[1],dp[2]=max(dp[1],dp[2])+l[i][0],max(dp[0],dp[2])+l[i][1],max(dp[0],dp[1])+l[i][2]
    print(dp)
print(max(dp))

Submission status: Wrong Answer

Solution code:
N = int(input())
abc = []
for _ in range(N):
	a, b, c = map(int, input().split())
	abc.append([a,b,c])
dp = [[0, 0, 0] for _ in range(N+1)]
print(abc)
for i in range(1,N+1):
	dp[i][0] = max(dp[i][0], dp[i-1][1]+abc[i-1][0])
	dp[i][0] = max(dp[i][0], dp[i-1][2]+abc[i-1][0])
	dp[i][1] = max(dp[i][1], dp[i-1][0]+abc[i-1][1])
	dp[i][1] = max(dp[i][1], dp[i-1][2]+abc[i-1][1])
	dp[i][2] = max(dp[i][2], dp[i-1][0]+abc[i-1][2])
	dp[i][2] = max(dp[i][2], dp[i-1][1]+abc[i-1][2])
	print(dp)

print(max(dp[N]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i],b[i],c[i] = map(int,input().split())

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)
for i in range(n):
    dpa[i] = max(dpb[i-1],dpc[i-1]) + a[i]
    dpb[i] = max(dpc[i-1],dpa[i-1]) + b[i]
    dpc[i] = max(dpa[i-1],dpb[i-1]) + c[i]
print(max(dpa[-1],dpb[-1],dpc[-1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
dp=[0]*n
for i in range(n):
	dp[i]=[0]*3
dp[0][0],dp[0][1],dp[0][2]=map(int,input().split())
for i in range(n-1):
	a,b,c=map(int,input().split())
	dp[i][0]=a+max(dp[i-1][2],dp[i-1][1])
	dp[i][1]=b+max(dp[i-1][0],dp[i-1][2])
	dp[i][2]=c+max(dp[i-1][0],dp[i-1][1])
print(max(dp[n-1]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())

abc = [[int(i) for i in input().split()] for j in range(n)]

def happy(n, abc):
    da, db, dc = 0, 0, 0
    for a, b, c in abc:
        na = max(db, dc) + a
        nb = max(dc, da) + b
        nc = max(da, db) + c
    da, db, dc = na, nb, nc

    return max(da, db, dc)

print(happy(n, abc))

Submission status: Wrong Answer

Solution code:
n = int(input())
joy = []

for i in range(n):
    cur = [int(i) for i in input().split()]
    joy.append(cur)
    
ans = 0

dp = [[0 for i in range(n+5)] for j in range(3)]

#dp(i,j) = ith prev, jth day

dp[0][n-1] = max(joy[n-1][1], joy[n-1][2])
dp[1][n-1] = max(joy[n-1][0], joy[n-1][2])
dp[2][n-1] = max(joy[n-1][1], joy[n-1][1])

for j in range(n-2, -1, -1):
    for i in range(3):
        for k in range(3):
            if k==i:
                continue
            dp[i][j] = max(dp[i][j], joy[j][k] + dp[k][j+1])
print(max(dp[0][0], dp[1][0], dp[2][0]))

#for i in range(3):
    #ans = max(ans, brute(0, i))
#print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b, c = 0, 0, 0

for i in range(n):
  x, y, z = map(int, input().split())
  a, b, c = a+max(y,z), b+max(x,z), c+max(x,y)
print(max(a,b,c))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Mar  5 21:42:06 2019

@author: avina
"""
n = int(input())
dp = [3 for i in range(n+1)]
s = 0
for i in range(1,n+1):
    c = [(u,int(v)) for u,v in enumerate(input().strip().split())]
    c.sort(key=lambda x : x[1],reverse=True)
    if c[0][0] == dp[i-1]:
         s += c[1][1]
         dp[i] = c[1][0]
    else:
        dp[i] = c[0][0]
        s+=c[0][1]
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())

happinesses_each_day = []
for n in range(N):
    happinesses_each_day.append(list(map(int, input().split())))

def get_max_and_index(list):
    index, max = (-1, 0)
    for i, l in enumerate(list):
        if max < l:
            index = i
            max = l
    return index, max


dp = [0] * N
prev = -1

for i, happinesses in enumerate(happinesses_each_day):
    if prev is not -1:
        happinesses[prev] = -1
    prev, dp[i] = get_max_and_index(happinesses)

print(sum(dp))

Submission status: Wrong Answer

Solution code:
n=int(input())
hd=[list(map(int,input().split())) for _ in range(n)]
A,B,C=0,0,0
for a,b,c in hd:
  A,B,C=A+max(b,c),B+max(a,c),C+max(a,b)
print(max(A,B,C))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for i in range(n):
  a,b,c=map(int,input().split())
  l.append([a,b,c])

dp=l[0]
print(dp)
for i in range(1,n):
    dp=[max(dp[1],dp[2])+l[i][0],max(dp[0],dp[2])+l[i][1],max(dp[0],dp[1])+l[i][2]]
print(max(dp))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for i in range(n):
  a,b,c=map(int,input().split())
  l.append([a,b,c])

dp=l[0]
print(dp)
for i in range(1,n):
    dp=[max(dp[1],dp[2])+l[i][0],max(dp[0],dp[2])+l[i][1],max(dp[0],dp[1])+l[i][2]]
    print(dp)
print(max(dp))

Submission status: Wrong Answer

Solution code:
N = int(input())
lis = [list(map(int, input().split())) for i in range(N)]

dp = [[0,0] for i in range(N)]
for idx, val in enumerate(lis):
	if idx == 0:
		dp[idx][0]=max(val)
		dp[idx][1]=val.index(max(val))
	else:
		if dp[idx-1][1] == val.index(max(val)):
			val[dp[idx-1][1]] = -1
		dp[idx][0] = dp[idx-1][0]+max(val)
		dp[idx][1] = val.index(max(val))
print(dp[-1][0])

Submission status: Wrong Answer

Solution code:
from sys import stdin
n=int(stdin.readline())
dp=[0]*3
for i in range(n):
    before=[i for i in dp]
    l=list(map(int,stdin.readline().split()))
    for i in range(3):
        dp[i]=max(before[i]+l[(i+1)%3],before[i]+l[(i+2)%3])
print(max(dp))

Submission status: Wrong Answer

Solution code:
def solve(actions, n):
    # 1-origin
    dp = [[0] * 4 for _ in range(n + 1)]

    for day, action in enumerate(actions, 1):
        action1, action2, action3 = action[0], action[1], action[2]
        for key in range(1, 4):
            if key == 1:
                dp[day][key] = action1 + max(dp[day - 1][2], dp[day - 1][3])
            elif key == 2:
                dp[day][key] = action2 + max(dp[day - 1][1], dp[day - 1][3])
            else:
                dp[day][key] = action3 + max(dp[day - 1][1], dp[day - 1][2])

    return dp[n][3]


def main():
    n = int(input())
    actions = []

    for i in range(n):
        actions.append(list(map(int, input().split())))

    ans = solve(actions, n)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
class Solution(object):
    def vacation(self, n, points):
        dp = [0 for _ in range(n)]
        dp[0] = max(points[0])
        prev_activity = []
        prev_activity.append(points[0].index(max(points[0])))
        # print('i:', 0, prev_activity)
        for i, point in enumerate(points[1:], 1):
            curr_activity = []
            for j in range(len(point)):
                if j not in prev_activity:
                    curr_activity.append(point[j])

            max_idx = point.index(max(curr_activity))
            dp[i] = dp[i-1] + point[max_idx]
            prev_activity.append(max_idx)

            if len(prev_activity) > 1:
                prev_activity.pop(0)

            # print('i:', i, prev_activity, 'curr_activity:', curr_activity)

        # print(dp)
        return dp[-1]







if __name__ == '__main__':
    n = int(input().strip())
    points = []
    for i in range(n):
        points.append(list(map(int, input().strip().split())))
    sol = Solution()
    res = sol.vacation(n, points)
    print(res)

Submission status: Wrong Answer

Solution code:
class Solution(object):
    def vacation(self, n, points):
        dp = [0 for _ in range(n)]
        dp[0] = max(points[0])
        prev_activity = []
        prev_activity.append(points[0].index(max(points[0])))
        # print('i:', 0, prev_activity)
        for i, point in enumerate(points[1:], 1):
            curr_activity = []
            for j in range(len(point)):
                if j not in prev_activity:
                    curr_activity.append(point[j])

            max_idx = point.index(max(curr_activity))
            dp[i] = dp[i-1] + point[max_idx]
            prev_activity.append(max_idx)

            if len(prev_activity) > 1:
                prev_activity.pop(0)

            # print('i:', i, prev_activity, 'curr_activity:', curr_activity)

        # print(dp)
        print(dp[-1])







if __name__ == '__main__':
    n = int(input().strip())
    points = []
    for i in range(n):
        points.append(list(map(int, input().strip().split())))
    sol = Solution()
    res = sol.vacation(n, points)
    print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
abc=[[0 for i in range(3)] for j in range(N)]
for i in range(N):
    A=list(map(int,input().split()))
    for j in range(3):
        abc[i][j]=A[j]
dp=[[0,-2] for i in range(N+1)]
for i in range(N):
    buf=[]
    for j in range(3):
        if dp[i][1]==-j:
            buf.append(-1000000)
            continue
        else:
            buf.append(dp[i][0]+abc[i][j])
    dp[i+1][0]=max(buf)
    dp[i+1][1]=buf.index(max(buf))
    if dp[i][1]==dp[i+1][1]:
        dp[i+1][1]=-dp[i+1][1]
print(dp[N][0])

Submission status: Wrong Answer

Solution code:
n = int(input())
import numpy as np
abc = np.array([[int(x) for x in input().split()] for y in range(n)],dtype=int)
dp = np.zeros((n,3),dtype=int)
dp[0] = abc[0]
for p in range(1,n):
    dp[p][0] = max(dp[p-1][1],dp[p-1][2]) + abc[p][0]
    dp[p][1] = max(dp[p-1][0],dp[p-1][2]) + abc[p][1]
    dp[p][2] = max(dp[p-1][0],dp[p-1][1]) + abc[p][2]
print(dp)
print(max(dp[n-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
table = [0]*n
activities = []
temp = []

for i in range(n):
    activities.append(list(map(int, input().split(" "))))

table[0] = max(activities[0])

x = activities[0].index((table[0]))
for i in range(1, n):
    temp = activities[i][:x] + activities[i][x+1:]
    x = activities[i].index(max(temp))
    table[i] = table[i-1] + max(temp)

print(table[n-1])

Submission status: Wrong Answer

Solution code:
# coding:utf-8

N = int(input())

# 予定リスト
schedule = []

for _ in range(N):
    schedule.append([int(i) for i in input().split()])

# 幸福度
happy = 0

# 行動ログ
actions = [None]*N

# 1日目
hi = max(schedule[0])
happy += hi
actions[0] = schedule[0].index(hi)

# 2日目以降
for i in range(1, N):
    _action = actions[i-1]
    if _action == 0:
        hi = max(schedule[i][1], schedule[i][2])
    elif _action == 1:
        hi = max(schedule[i][0], schedule[i][2])
    else:
        hi = max(schedule[i][0], schedule[i][1])
    happy += hi
    actions[i] = schedule[i].index(hi)

print(happy)

Submission status: Wrong Answer

Solution code:
N=int(input())

shonichi=list(map(int,input().split()))
choice=shonichi.index(max(shonichi))
score=max(shonichi)

for n in range(1,N):
  #print(score)
  happy=list(map(int,input().split()))
  happy[choice]=0
  maximum=max(happy)
  score+=maximum
  choice=happy.index(maximum)
  happy=[]
  
print(score)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
B = []
C = []

for i in range(N):
	a,b,c = map(int,input().split())
	A.append(a)
	B.append(b)
	C.append(c)

dp = []

for i in range(N):
	dp.append(0)


dp[0] = max(A[0],B[0],C[0])

for i in range(N-1):
	if dp[i] == A[i]:
		dp[i+1] = max(dp[i+1], max(B[i+1],C[i+1]))
	elif dp[i] == B[i]:
		dp[i+1] = max(dp[i+1], max(C[i+1],A[i+1]))
	elif dp[i] == C[i]:
		dp[i+1] = max(dp[i+1], max(A[i+1],B[i+1]))

print(sum(dp))

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [0] * 3

for i in range(n):
    a, b, c = map(int, input().split())
    dp = [a + max(dp[1], dp[2]), b + max(dp[0], dp[2]), c + max(dp[1], dp[2])]
          
print(max(dp))

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [[0] * 3 for _ in range(n)]

dp[0] = list(map(int, input().split()))
for i in range(1, n):
    a, b, c = map(int, input().split())
    dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2])
    dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2])
    dp[i][2] = c + max(dp[i - 1][1], dp[i - 1][1])
    
print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b,c=0,0,0
for i in range(n):
    x,y,z=map(int,input().split())
    a,b,c=max(b,c)+x,max(a,c)+y,max(a,b)+z
    print(a,b,c)
print(max(a,b,c))

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

n, = I()
l = []
for i in range(n):
    l.append(I())
ans = [0]*(n+1)
ans[0] = max(l[0])
m = -MOD
index = l[0].index(max(l[0]))
mindex = 0
if n > 1:
    for i in range(3):
        if l[1][i] + ans[0] > m and i != index:
            m = l[1][i] + ans[0]
            mindex = i
ans[1] = m
index = mindex
for i in range(2, n):
    m = -MOD
    for j in range(3):
        if l[i][j] + ans[i-1] > m and j != index:
            m = l[i][j] + ans[i-1]
            mindex = j
    if l[i][index] + ans[i-2] > m:
        m = l[i][index] + ans[i-2]
        mindex = index
    ans[i] = m
    index = mindex
# print(ans)
print(ans[n-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]
dp = [A[0][0], A[0][1], A[0][2]]

for i in range(1, n):
    dp = [dp[0] + max(A[i][1], A[i][2]), dp[1] + max(A[i][0], A[i][2]), dp[2] + max(A[i][0], A[i][1])]

print(max(dp))

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [int(i) for i in input().split()]

for i in range(n-1):
    a, b, c = map(int, input().split())
    dp[0] = max(b, c) + dp[0]
    dp[1] = max(a, c) + dp[1]
    dp[2] = max(a, b) + dp[2]
    
print(max(dp))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N = int(sys.stdin.readline().strip())

a_list = [None for _ in range(N)]
b_list = [None for _ in range(N)]
c_list = [None for _ in range(N)]

for i in range(N):
    a, b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    a_list[i] = a
    b_list[i] = b
    c_list[i] = c

tmp = [a_list, b_list, c_list]
happy = [0 for _ in range(N)]
select = [None for _ in range(N)]

ind = np.argmax([a_list[0], b_list[0], c_list[0]])
select[0] = [0, 1, 2][ind]
happy[0] = [a_list[0], b_list[0], c_list[0]][ind]

if N == 1:
    print(happy[0])
    sys.exit()

ind = np.argmax([a_list[0] + b_list[1], a_list[0] + c_list[1], b_list[0] + a_list[1], b_list[0] + c_list[1], c_list[0] + a_list[1], c_list[0] + b_list[1]])
happy[1] = [a_list[0] + b_list[1], a_list[0] + c_list[1], b_list[0] + a_list[1], b_list[0] + c_list[1], c_list[0] + a_list[1], c_list[0] + b_list[1]][ind]
select[1] = [1, 2, 0, 2, 0, 1][ind]

if N == 2:
    print(happy[1])
    sys.exit()

for i in range(2, N):
    max_h = 0
    for j in range(3):
        for k in range(3):
            if k == j:
                continue
            if j == select[i-2]:
                continue
            if max_h < tmp[k][i] + tmp[j][i-1] + happy[i-2]:
                max_h = tmp[k][i] + tmp[j][i-1] + happy[i-2]
                select[i] = k
            #print(tmp[k][i-1], tmp[j][i-2])
    happy[i] = max_h

print(happy[N-1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def dp_happiness(N):
    yesterday_a, yesterday_b, yesterday_c = 0, 0, 0
    for _ in range(N):
        today_a, today_b, today_c = map(int, input().split())
        happiness_a = today_a + max(yesterday_b, yesterday_c)
        happiness_b = today_b + max(yesterday_c, yesterday_a)
        happiness_c = today_c + max(yesterday_a, yesterday_b)
    return max(happiness_a, happiness_b, happiness_c)

N = int(input())
print(dp_happiness(N))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def dp_happiness(N, lst):
    lst_happiness = [0] * N
    lst_happiness[0] = max(lst[0])
    indx = lst[0].index(lst_happiness[0])
    
    for i in range(1, N):
        if indx==0:
            val = max(lst[i][1], lst[i][2])
            lst_happiness[i] = lst_happiness[i-1] + val
        elif indx==1:
            val = max(lst[i][2], lst[i][0])
            lst_happiness[i] = lst_happiness[i-1] + val
        else:
            val = max(lst[i][0], lst[i][1])
            lst_happiness[i] = lst_happiness[i-1] + val
        indx = lst[i].index(val)
    return lst_happiness

N = int(input())
lst_vacation = [list(map(int, input().split())) for _ in range(N)]
print(dp_happiness(N, lst_vacation)[N-1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def dp_happiness(N, lst):
    lst_happiness = [0] * N
    lst_happiness[0] = max(lst[0])
    indx = lst[0].index(lst_happiness[0])
    
    for i in range(1, N):
        if indx==0:
            val = max(lst[i][1], lst[i][2])
            lst_happiness[i] = lst_happiness[i-1] + val
        elif indx==1:
            val = max(lst[i][2], lst[i][0])
            lst_happiness[i] = lst_happiness[i-1] + val
        else:
            val = max(lst[i][0], lst[i][1])
            lst_happiness[i] = lst_happiness[i-1] + val
        indx = lst[i].index(val)
    return lst_happiness

N = int(input())
lst_vacation = [list(map(int, input().split())) for _ in range(N)]
print(dp_happiness(N, lst_vacation))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def dp_happiness(N, lst):
    happiness = max(lst[0])
    indx = lst[0].index(happiness)
    for i in range(1, N):
        lst_day = lst[i]
        if indx == 0:
            max_val = max(lst_day[1], lst_day[2])
        elif indx == 1:
            max_val = max(lst_day[2], lst_day[0])
        else:
            max_val = max(lst_day[0], lst_day[1])
        indx = lst_day.index(max_val)
        happiness += max_val
    return happiness

N = int(input())
lst_vacation = [list(map(int, input().split())) for _ in range(N)]
print(dp_happiness(N, lst_vacation))

Submission status: Wrong Answer

Solution code:
N = int(input())
a_list = [[0 for _ in range(3)] for _ in range(N)]

for i in range(N):
    a, b, c = map(int, input().split())
    a_list[i][0] = a
    a_list[i][1] = b
    a_list[i][2] = c

dp = [[-1 for _ in range(3)] for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(3):
        for k in range(3):
            if i == 1:
                dp[i][j] = a_list[i - 1][k]
            if j == k:
                continue
            else:
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a_list[i - 1][j])

print(max(dp[N]))

Submission status: Wrong Answer

Solution code:
N = int(input())
happy = [list(map(int, input().split())) for _ in range(N)]

# i日目までの幸福度の最大値
dp = [0] * (N+1)

act = None
for i in range(N):
    act, dp[i+1] = max([(j, dp[i] + x) for j, x in [(j, x) for j, x in enumerate(happy[i]) if j != act]], key=lambda x: x[1])

print(dp[-1])