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:
s,t=0,-1
for _ in range(int(input())):
    a,b,c=map(int,input().split())
    if t==1:
        if b>c:
            s+=b
            t=2
        else:
            s+=c
            t=3
    elif t==2:
        if a>c:
            s+=a
            t=1
        else:
            s+=c
            t=3
    elif t==3:
        if a>b:
            s+=a
            t=1
        else:
            s+=b
            t=2
    else:
        s+=max(a,b,c)
        if a>b and a>c:
            t=1
        elif b>c:
            t=2
        else:
            t=3
print(s)

Submission status: Wrong Answer

Solution code:
s,t=0,-1
for _ in range(int(input())):
    a,b,c=map(int,input().split())
    if t==1:
        if b>c:
            s+=b
            t=2
        else:
            s+=c
            t=3
    elif t==2:
        if a>c:
            s+=a
            t=1
        else:
            s+=c
            t=3
    elif t==3:
        if a>b:
            s+=a
            t=1
        else:
            s+=b
            t=2
    else:
        s+=max(a,b,c)
print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[]
B=[]
C=[]
for _ in range(n):
    a,b,c=map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)
happymax=[0]*(n+1)
happymax[1]=A[0]
for j in range(2,n+1):
    if happymax[j-1]-happymax[j-2]==A[j-2]:
        happymax[j]=happymax[j-1]+max(B[j-1],C[j-1])
    elif happymax[j-1]-happymax[j-2]==B[j-2]:
        happymax[j]=happymax[j-1]+max(A[j-1],C[j-1])
    else:
        happymax[j]=happymax[j-1]+max(A[j-1],B[j-1])
amax=happymax[n]
happymax=[0]*(n+1)
happymax[1]=B[0]
for j in range(2,n+1):
    if happymax[j-1]-happymax[j-2]==A[j-2]:
        happymax[j]=happymax[j-1]+max(B[j-1],C[j-1])
    elif happymax[j-1]-happymax[j-2]==B[j-2]:
        happymax[j]=happymax[j-1]+max(A[j-1],C[j-1])
    else:
        happymax[j]=happymax[j-1]+max(A[j-1],B[j-1])
bmax=happymax[n]
happymax=[0]*(n+1)
happymax[1]=C[0]
for j in range(2,n+1):
    if happymax[j-1]-happymax[j-2]==A[j-2]:
        happymax[j]=happymax[j-1]+max(B[j-1],C[j-1])
    elif happymax[j-1]-happymax[j-2]==B[j-2]:
        happymax[j]=happymax[j-1]+max(A[j-1],C[j-1])
    else:
        happymax[j]=happymax[j-1]+max(A[j-1],B[j-1])
cmax=happymax[n]    
print(max(amax,bmax,cmax))

Submission status: Wrong Answer

Solution code:
######## Biscuits   ###########3
N = int(input())
a = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for i in range(3)] for j in range(N + 1)]

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

print(max(dp[N]))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for i in range(3)] for j in range(N)]
dp[0] = a[0]

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines       
    N = int(readline())
    m = map(int,read().split())
    print(m)
    ABC = zip(m,m,m)
    print(ABC)
    x,y,z = 0,0,0 # 最後の活動 -> 幸福度のmax
    for a,b,c in ABC:
        x,y,z = max(y,z)+a,max(x,z)+b,max(x,y)+c        
        answer = max(x,y,z)
        print(answer)
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# print(*dp, sep='\n')
print(max(dp[N-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
prev = -1
ans = 0
for _ in range(N):
    abc = list(map(int, input().split()))
    mv = 0
    for i, whi in enumerate(abc):
        if i == prev:
            continue
        if mv < whi:
            mv = whi
    prev = abc.index(mv)
            # print(prev)
    # print(mv)
    ans += mv

print(ans)

Submission status: Wrong Answer

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

dp = [[0,0,0] for _ in range(n)]
dp[0][0], dp[0][1], dp[0][2] = l[0][0], l[0][1], l[0][2]

for i in range(1, n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][k] = max(dp[i][k], dp[i-1][j] + l[i][k])
print(dp)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    act = [[0 for i in range(3)] for j in range(N)]

    for i in range(N):
        act[i] = [int(x) for x in input().split()]


    DP = [[0 for i in range(3)] for j in range(N)]

    DP[0] = act[0]
    
    for i in range(N-1):
        for x in range(3):
            for y in range(3):
                if x != y:
                    DP[i+1][y] = max(DP[i+1][y],DP[i][x]+act[i+1][y])
                    print(DP)

    print(max(DP[-1]))

if __name__ == "__main__":
    main()
    pass

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    act = [[0 for i in range(3)] for j in range(N)]

    for i in range(N):
        act[i] = [int(x) for x in input().split()]

    print(act)

    DP = [[0 for i in range(3)] for j in range(N)]

    DP[0] = act[0]

    print(DP)
    
    for i in range(N-1):
        for x in range(3):
            for y in range(3):
                if x != y:
                    DP[i+1][y] = max(DP[i+1][y],DP[i][x]+act[i+1][y])
                    print(DP)

    print(max(DP[-1]))

if __name__ == "__main__":
    main()
    pass

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A, B, C = [[0 for i in range(N)] for j in range(3)]

    for i in range(N):
        A[i], B[i], C[i] = [int(x) for x in input().split()]

    print(A,B,C)

    DP = [[0 for i in range(3)] for j in range(N)]

    act = [A,B,C]

    for i, X in enumerate(act):
        DP[0][i] = X[0]
    
    for i in range(N-1):
        for x, X in enumerate(act):
            for y, Y in enumerate(act):
                if x != y:
                    DP[i+1][y] = max(DP[i+1][y],DP[i][x]+Y[i+1])
                    print(DP)

    print(max(DP[-1]))

if __name__ == "__main__":
    main()
    pass

Submission status: Wrong Answer

Solution code:
N=int(input())
dp=[[0]*3 for i in range(N)]
for i in range(1,N):
  a=list(map(int,input().split()))
  for j in range(3):
    for k in range(3):
      if j==k:
        continue
      dp[i][k]=max(dp[i][k],dp[i-1][j]+a[k])
print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
dp=[[0]*3 for i in range(N+1)]
for i in range(1,N):
  a=list(map(int,input().split()))
  for j in range(3):
    for k in range(3):
      if j==k:
        continue
      dp[i][k]=max(dp[i][k],dp[i-1][j]+a[k])
print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
dp=[[0]*3 for i in range(N)]#今回は正の範囲で最大値をもとめたいので0で初期化
for i in range(N):
  a=list(map(int,input().split()))
  for j in range(3):
    for k in range(3):
      if k!=j:
        dp[i][j]=max(dp[i-1][k]+a[j],dp[i][j])
print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    HAPPY = [list(map(int, input().split())) for i in range(N)]
    # dp = [[0]*3 for i in range(N+1)]
    dp = [[0]*3]*(N+1)
    for i in range(N):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i+1][k] = max(dp[i+1][k], HAPPY[i][k] + dp[i][j])
    print(max(max(dp[N][0], dp[N][1]), dp[N][2]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
#n,k=map(int,input().split())
n=int(input())
abc=[]
for _ in range(n):
      abc.append(list(map(int,input().split())))
dp=np.zeros(n+1)
# dp[i]:i日目までの最大。dp[0]=0。求めるのはdp[n]
dp[1]=max(abc[0])
op1=[i for i in range(3) if abc[0][i]!=dp[1]]
if len(op1)<2:
      op1=[0,1,2]
op2=[0,1,2]
for i in range(2,n+1):
      m=max([abc[i-1][j] for j in op1])
      m1=dp[i-1]+m
      op=[j for j in range(3) if abc[i-1][j]!=m]
      if len(op)<2:
            op=[0,1,2]
      opt=[j for j in range(3) if abc[i-1][j]!=max(abc[i-1])]
      if len(opt)<2:
            opt=[0,1,2]
      m2=dp[i-2]+max(abc[i-1])
      m2=+max([abc[i-2][j] for j in set(op2).intersection(set(opt))])
      dp[i]=max(m1,m2)
      op2=op1
      op1=op

print(int(dp[-1]))

Submission status: Wrong Answer

Solution code:
# 初期入力
N = int(input())
koufuku = [list(map(int, input().split())) for i in range(N)] 
dp_ko = [0]*(N+1) 

dp_ko[0] = max( koufuku[0] ) , koufuku[0].index(max(koufuku[0])) 

#
for i in range(N-1):
    tomorr_sort =sorted(koufuku[i+1]) # 翌日の幸福度を昇順でソート
    tomorr_max = tomorr_sort[-1] # 翌日の最大値
    tomorr_i = koufuku[i+1].index(tomorr_sort[-1]) # 翌日の最大値のindex
     # 翌日最大値のindex not 当日の保存していたindex(当日の最大値とは限らない)
    if tomorr_i != dp_ko[i][1]:
        dp_ko[i+1] = dp_ko[i][0] + tomorr_max , tomorr_i # 累積＋翌日の最大値 , 翌日のindex
    else:
        tomorr_no2 = tomorr_sort[-2] # 翌日2番目に大きい値
        tomorr_no2_i = koufuku[i+1].index(tomorr_sort[-2]) # 翌日2番目に大きい値のindex
        dp_ko[i+1] = dp_ko[i][0] + tomorr_no2 , tomorr_no2_i 

print(dp_ko[N-1][0])

Submission status: Wrong Answer

Solution code:
# 初期入力
N = int(input())
import numpy as np
koufuku = np.array( [list(map(int, input().split())) for i in range(N)] )
dp_kof = [0]*(N)


#
dp_kof[0] = ( max( koufuku[0,:] ) , np.argmax(koufuku[0,:]) )

for i in range(N-1):
    # 翌日最大値のindex not 当日の保存していたindex(前日があるので、当日の最大値とは限らない)
    tomorr_i = np.argmax(koufuku[i+1,:]) # 翌日の最大値のindex
    tomorr_ko = koufuku[i+1,:]              #翌日の幸福LIST
    dp_i = dp_kof[i][1]                # 当日の最大値の添え字（dp）
    today_ko = koufuku[i,:]              #当日の幸福LIST
    if tomorr_i != dp_i: 
        dp_kof[i+1] =( dp_kof[i][0] + np.max(tomorr_ko) , tomorr_i)# 累積＋翌日の最大値,index
    else:
        tomorr_no2 = np.sort(tomorr_ko)[-2] # 2番目に大きい値
        tomorr_no2_i = koufuku[i+1].argsort()[-2] # 2番目に大きい値のindex
        dp_kof[i+1] =( dp_kof[i][0] + tomorr_no2 , tomorr_no2_i ) # 累積＋2番目に大きい値,index

print(dp_kof[N-1][0])

Submission status: Wrong Answer

Solution code:
N = int(input())
Q = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*3 for i in range(N)]
dp[0][0] = Q[0][0]
dp[0][1] = Q[0][1]
dp[0][2] = Q[0][2]

print(dp)
for i in range(1, N):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + Q[i][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + Q[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + Q[i][2]
print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
dp=[0]*(N+1)


for i in range(N):
    a,b,c = map(int,input().split())
    if i == 0:
        dp[i+1] = dp[i]+max(a,b,c)
        flg = [a,b,c].index(max([a,b,c]))
    else:
        if flg==0:
            dp[i+1] = dp[i] + max(b,c)
            flg = [a,b,c].index(max([b,c]))
        elif flg==1:
            dp[i+1] = dp[i] + max(a,c)
            flg = [a,b,c].index(max([a,c]))
        else:
            dp[i+1] = dp[i] + max(a,b)
            flg = [a,b,c].index(max([a,b]))

# print(dp)
print(dp[N])

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
dp=np.zeros(N+1,dtype=int)


for i in range(N):
    a,b,c = map(int,input().split())
    if i == 0:
        dp[i+1] = dp[i]+max(a,b,c)
        flg = [a,b,c].index(max([a,b,c]))
    else:
        if flg==0:
            dp[i+1] = dp[i] + max(b,c)
            flg = [a,b,c].index(max([b,c]))
        elif flg==1:
            dp[i+1] = dp[i] + max(a,c)
            flg = [a,b,c].index(max([a,c]))
        else:
            dp[i+1] = dp[i] + max(a,b)
            flg = [a,b,c].index(max([a,b]))

# print(dp)
print(dp[N])

Submission status: Wrong Answer

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

n = int(input())
abc = [[int(x) for x in input().split()] for _ in range(n)]

dp = [[0] * 3 for _ in range(n)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][1] = abc[0][2]

for i in range(1, n):
    a, b, c = abc[i]
    dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)
    dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)
    dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)

print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())

dp = [[0] * 3 for _ in range(N)]

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N)]
for i in range(N):
  if i == 0:
    dp[i] = T[i]
  for j in [0,1,2]:
    dp[i][j] = max([dp[i-1][j1]+T[i][j] for j1 in [0,1,2] if j1 != j])
print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    ABC = [list(map(int, input().split())) for _ in [0] * N]

    dp = [[0, 0, 0] for _ in [0] * N]
    dp[0] = ABC[0][:]
    for i in range(1, N):
        dp[i][0] = max(dp[i-1][0] + ABC[i][1], dp[i-1][0] + ABC[i][2])
        dp[i][1] = max(dp[i-1][1] + ABC[i][0], dp[i-1][1] + ABC[i][2])
        dp[i][2] = max(dp[i-1][2] + ABC[i][0], dp[i-1][2] + ABC[i][1])
    print(max(dp[-1]))


main()

Submission status: Wrong Answer

Solution code:
N = int(input())

#dp = [[0] * 3 for _ in range(N)]
dp = [[0]*3]*N

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

dp[0][0]=arr[0][0]
dp[0][1]=arr[0][1]
dp[0][2]=arr[0][2]


for i in range(1,N,1):
    dp[i][0] = max(arr[i][0]+dp[i-1][1],arr[i][0]+dp[i-1][2])
    dp[i][1] = max(arr[i][1]+dp[i-1][0],arr[i][1]+dp[i-1][2])
    dp[i][2] = max(arr[i][2]+dp[i-1][0],arr[i][2]+dp[i-1][1])

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

Submission status: Wrong Answer

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

if n==1:
    print(max(H[0][0],H[0][1],H[0][2]))
    exit()
dp=[[0,0,0]for j in range(n+1)]
for i in range(3):
    dp[0][1]=H[0][i]

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

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

Submission status: Wrong Answer

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

if n==1:
    print(max(H[0][0],H[0][1],H[0][2]))
    exit()
dp=[[0,0,0]for j in range(n)]
for i in range(3):
    dp[0][1]=H[0][i]

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

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

Submission status: Wrong Answer

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

ans=0
dp=[[0 for _ in range(3)]for j in range(n)]
for i in range(3):
    dp[0][1]=H[0][i]

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
h=[]
for i in range(n):
    p,q,r=map(int,input().split())
    h.append([p,q,r])

dp=[[0 for _ in range(3)]]*(n+1)
dp[0][0]=h[0][0]
dp[0][1]=h[0][1]
dp[0][2]=h[0][2]

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    n = int(input())
    ary = [list(map(int, stdin.readline().split())) for _ in range(n)]
    dp = [[]] * n

    def max_act(abc,yesterday=None):
        if yesterday:
            del abc[yesterday]
        v = max(abc)
        i = abc.index(v)
        return [i,v]

    dp[0] = max_act(ary[0])

    for i in range(1,n):
        dp[i] = max_act(ary[i],dp[i-1][0])
    print(sum([i[1] for i in dp]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def chmax_a(l,B,C,i):
	return max(B+l[i][1],C+l[i][2])

def chmax_b(l,A,C,i):
	return max(A+l[i][0],C+l[i][2])

def chmax_c(l,A,B,i):
	return max(B+l[i][1],A+l[i][0])

N=int(input())
happiness=[]
for i in range(N):
	cost=list(map(int,input().split()))
	happiness.append(cost)
answers=[]
A=0
B=0
C=0
for i in range(N-1,-1,-1):
	a=chmax_a(happiness,B,C,i)
	b=chmax_b(happiness,A,C,i)
	c=chmax_c(happiness,A,B,i)
	A=a
	B=b
	C=c
	print('{0}, {1}, {2}'.format(A,B,C))
print(max(A,B,C))

Submission status: Wrong Answer

Solution code:
def dynamic(a, b, c):
  
  if i == 0:
    dp[1] = max(a, b, c)
  
  elif dp[i] == dp[i-1] + A[i-1]:
    if A[i-1] == B[i-1] or A[i-1] == C[i-1]:
      dp[i+1] = dp[i] + max(A[i], B[i], C[i])
    else:
      dp[i+1] = dp[i] + max(B[i], C[i])
  
  elif dp[i] == dp[i-1] + B[i-1]:
    if B[i-1] == C[i-1]:
      dp[i+1] = dp[i] + max(A[i], B[i], C[i])
    else:
      dp[i+1] = dp[i] + max(A[i], C[i])
  
  elif dp[i] == dp[i-1] + C[i-1]:
    dp[i+1] = dp[i] + max(B[i], A[i])
    
  return dp[i+1]

n = int(input())
dp = [0]*(n+1)
A = []
B = []
C = []
for i in range(n):
  a, b, c = map(int, input().split())
  A.append(a)
  B.append(b)
  C.append(c)
  dynamic(a, b, c)
  
print(dp[-1])

Submission status: Wrong Answer

Solution code:
def dynamic(a, b, c):
  if i == 0:
    dp[1] = max(a, b, c)
  elif dp[i] == dp[i-1] + A[i-1]:
    dp[i+1] = dp[i] + max(B[i], C[i])
  elif dp[i] == dp[i-1] + B[i-1]:
    dp[i+1] = dp[i] + max(A[i], C[i])
  elif dp[i] == dp[i-1] + C[i-1]:
    dp[i+1] = dp[i] + max(B[i], A[i])
    
  return dp[i+1]

n = int(input())
dp = [0]*(n+1)
A = []
B = []
C = []
for i in range(n):
  a, b, c = map(int, input().split())
  A.append(a)
  B.append(b)
  C.append(c)
  dynamic(a, b, c)
  
print(dp[-1])

Submission status: Wrong Answer

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

table = [[0]*3 for i in range(N)]


for i in range(0, N):# i日目
    if i == 0:
        table[i] = ABC[i]
    else:
        for j in range(3): #a,b,c
            table[i][j] = max(
                [table[i-1][j1] + ABC[i][j1] for j1 in range(3) if  j1 != j]
                 )
        # print(table)
        
print(max(table[-1]))

Submission status: Wrong Answer

Solution code:
# 行数
N = int(input().strip())

# 2次元配列
taro = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    taro.append(array)
#3
#10 40 70
#20 50 80
#30 60 90

happy = [0]*(N+1)
for i in range(1,N+1):
    if i == 1:
        happy[i] = max(taro[i-1])
    elif i == 2:
        happy[i] = max(sorted(taro[i-2])[-2]+max(taro[i-1]),happy[i-1]+sorted(taro[i-1])[-2])
    else:
        happy[i] = max(happy[i-2]+sorted(taro[i-2])[-2]+max(taro[i-1]),
                       happy[i-1]+sorted(taro[i-1])[-2])

print(happy[-1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    work_list = [tuple(map(int, input().split())) for i in range(n)]

    total = 0
    target = {0, 1, 2}
    pre = {-1}
    for work in work_list:
        max_val = 0
        now_target = target - pre
        for i in now_target:
            if max_val < work[i]:
                max_val = work[i]
                pre = {i}
        total += max_val

    print(total)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    work_list = [tuple(map(int, input().split())) for i in range(n)]

    total = 0
    target = {0, 1, 2}
    pre = {-1}
    for work in work_list:
        max_val = 0
        for i in target - pre:
            if max_val < work[i]:
                max_val = work[i]
                pre = {i}
        total += max_val

    print(total)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n+1)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1][j] = max(dp[i+1][j], dp[i][j]+a[i][k])
print(max(dp[n]))

Submission status: Wrong Answer

Solution code:
n = int(input())
pre = -1
ans = 0
for i in range(n):
    a_b_c = list(map(int, input().split()))
    ma = 0
    for j in range(3):
        if j != pre:
            if ma < a_b_c[j]:
                ma = a_b_c[j]
                ppre = j
    pre = ppre
    ans += ma
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

days = []
for day in range(n):
  a_i, b_i, c_i = map(int, input().split())
  days.append((a_i, b_i, c_i))

dp = {} # (is repetition, activity today, day number) -> happiness up to that day

for activity in range(3):
  dp[True, activity, -1] = 0
  dp[False, activity, -1] = 0

for day in range(n):
  for activity in range(3):
    dp[True, activity, day] = days[day][activity] + dp[False, activity, day - 1]
    dp[False, activity, day] = days[day][activity] + max(
      dp[False, (activity + 1) % 3, day - 1],
      dp[True, (activity + 1) % 3, day - 1],
      dp[False, (activity - 1) % 3, day - 1],
      dp[True, (activity - 1) % 3, day - 1]
    )

answer = -1
for activity in range(3):
  answer = max(answer, dp[True, activity, n - 1], dp[False, activity, n - 1])
    
print(answer)

Submission status: Wrong Answer

Solution code:
N=int(input())
L = [list(map(int, input().split())) for i in range(N)]
dp=[[0 for j in range(3)] for i in range(N)]

for i in range(N):
  for P in range(3):
    for PY in range(3):
      if P==PY:
        continue
      elif i==0:
        dp[i][P]=L[i][P]
      else:
        dp[i][P]=max(dp[i][P],dp[i-1][PY]+L[i-1][P])
ans=0
for i in range(3):
  ans=max(ans,dp[N-1][i])
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
L = [list(map(int, input().split())) for i in range(N)]
dp=[[0 for j in range(3)] for i in range(N)]
ans=[0]*(N+1)
for i in range(N):
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+L[i][0]
  dp[i][1]=max(dp[i-1][2],dp[i-1][0])+L[i][1]
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+L[i][2]
  ans=max(dp[i][0],dp[i][1],dp[i][2])
  #print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# Vacation

'''
3
10 40 70
20 50 80
30 60 90
'''

N = int(input())

dp = [[None] * 3 for _ in range(N)]
dp[0] = list(map(int, input().split()))
# print(dp)

for i in range(1, N):
    data = list(map(int, input().split()))
    print(data)

    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + data[0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + data[1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + data[2]

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [[0] * N for i in range(3)]
a[1][0] = 1
a[2][0] = 2
dp = [[0] * N for i in range(3)]
x, y, z = map(int, input().split())
dp[0][0] = x
dp[1][0] = y
dp[2][0] = z

for i in range(1, N):
    x, y, z = map(int, input().split())
    for j in range(3):
        k = a[j][i - 1]
        if k == 0:
            dp[j][i] = dp[j][i - 1] + max(y, z)
            if max(y, z) == y:
                a[j][i] = 1
            else:
                a[j][i] = 2
        elif k == 1:
            dp[j][i] = dp[j][i - 1] + max(x, z)
            if max(x, z) == x:
                a[j][i] = 0
            else:
                a[j][i] = 2
        else:
            dp[j][i] = dp[j][i - 1] + max(x, y)
            if max(x, y) == x:
                a[j][i] = 0
            else:
                a[j][i] = 1

ret = 0
for i in range(3):
    ret = max(ret, dp[i][-1])
print(ret)

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] * 3 for i in range(N + 1)]

for i, abc in enumerate(ABC):

  dp_i = i + 1

  if(dp_i == 1):
    dp[dp_i][0] = abc[0]
    dp[dp_i][1] = abc[1]
    dp[dp_i][2] = abc[2]
    continue
  for j, cur_dp_val in enumerate(dp[dp_i]):
    max_dp_val = cur_dp_val
    for k, happy_v in enumerate(abc):

      if(j == k):
        continue


      if(max_dp_val < dp[dp_i - 1][j] + happy_v):
        max_dp_val = dp[dp_i - 1][j] + happy_v
    
    dp[dp_i][j] = max_dp_val

print(max(dp[N]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    x = []
    for _ in range(n):
        a, b, c = map(int, input().split())
        x.append((a, b, c))
    dp0 = [0]*(n+1)
    dp1 = [0]*(n+1)
    dp2 = [0]*(n+1)
    for i in range(1,n+1):
        a, b, c = x[0]
        dp0[i] = max(dp1[i-1]+a, dp2[i-1]+a)
        dp1[i] = max(dp0[i-1]+b, dp2[i-1]+b)
        dp2[i] = max(dp0[i-1]+c, dp1[i-1]+c)
    print(max(dp0[n], dp1[n], dp2[n]))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# C - Vacation
import numpy as np

N = int(input())
value = np.zeros((N, 3))
for i in range(N):
    value[i, :] = list(map(int, input().split()))
value = value.tolist()

dp = [0]*3

for a, b, c in value:
    dp = [max(dp[1], dp[2])+a, max(dp[0], dp[2])+b, max(dp[0], dp[1])+c]
    
print(max(dp))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
M = np.zeros((N, 3), np.uint16)
for i in range(N):
    M[i, 0:3] = list(map(int, input().split()))
h = [0] * N
h[0] = max(M[0, 0:3])
m = [0] * N
i = 0
if (h[0] == M[0, 0]):
    m[0] = 'a'
elif (h[0] == M[0, 1]):
    m[0] = 'b'
else:
    m[0] = 'c'
for i in range(N - 1):
    if (m[i] == 'a'):
        h[i + 1] = max(M[i + 1, 1], M[i + 1, 2])
        if (h[i + 1] == M[i + 1, 1]):
            m[i + 1] = 'b'
        elif (h[i + 1] == M[i + 1, 2]):
            m[i + 1] = 'c'
    elif (m[i] == 'b'):
        h[i + 1] = max(M[i + 1, 0], M[i + 1, 2])
        if (h[i + 1] == M[i + 1, 0]):
            m[i + 1] = 'a'
        elif (h[i + 1] == M[i + 1, 2]):
            m[i + 1] = 'c'
    else:
        h[i + 1] = max(M[i + 1, 0], M[i + 1, 1])
        if (h[i + 1] == M[i + 1, 0]):
            m[i + 1] = 'a'
        elif (h[i + 1] == M[i + 1, 1]):
            m[i + 1] = 'b'
print(sum(h))

Submission status: Wrong Answer

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

last_index = -1
value = 0
for i in range(n):
    sorted_lst = sorted(abc[i], reverse=True)
    for j in range(3):
        if j == last_index:
            continue
        last_index = j
        value += sorted_lst[j]
        break
print(value)

Submission status: Wrong Answer

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

back = -1
for i in range(N):
  tmp = l
  if back != -1:
      tmp[i][back] = 0
  ans.append(max(tmp[i]))
  back = l[i].index(max(tmp[i]))

print(sum(ans))

Submission status: Wrong Answer

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

back = -1
for i in range(N):
  tmp = l
  if back != -1:
    tmp[i][back] = 0
  ans.append(max(tmp[i]))
  back = l[i].index(max(tmp[i]))

print(sum(ans))