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:
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
dp=[[0]*3 for _  in range(n)]
dp[0]=[a[0][0],a[0][1],a[0][2]]
for i in range(n-1):
    for j in range(2):
        for k in range(2):
            if j!=k:
                dp[i+1][j]=max(dp[i+1][j],dp[i][k] + a[i+1][j])
            else:
                pass

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline()
############# CODE STARTS HERE #############
n=ii()
a, b, c=mi()
for _ in range(n-1):
    x, y, z=mi()
    a+=max(y, z)
    b+=max(x, z)
    c+=max(y, x)
print(max(a, b, c))

Submission status: Wrong Answer

Solution code:
from sys import stdin
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline()
############# CODE STARTS HERE #############
n=ii()
a, b, c=mi()
for _ in range(n-1):
    x, y, z=mi()
    a+=max(y, z)
    b+=max(x, z)
    c+=max(y, z)
print(max(a, b, c))

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b,c=[],[],[]
for i in range(n):
    x,y,z=map(int,input().split(" "))
    a.append(x)
    b.append(y)
    c.append(z)
dp=[[0,0,0] for i in range(n)]
# print(dp)
# print(a,b,c)
if a[0]>b[0]:
    if a[0]>c[0]:
        dp[0][0]=a[0]
    else:
        dp[0][2]=c[0]
else:
    if b[0]>c[0]:
        dp[0][1]=b[0]
    else:
        dp[0][2]=c[0]
# print(dp[0][0],dp[0][1],dp[0][2])
for i in range(1,n):
    if(dp[i-1][0]!=0):
        if(b[i]>c[i]):
            dp[i][1]=dp[i-1][0]+b[i]
        else:
            dp[i][2]=dp[i-1][0]+c[i]
    elif(dp[i-1][1]!=0):
        if(a[i]>c[i]):
            dp[i][0]=dp[i-1][1]+a[i]
        else:
            dp[i][2]=dp[i-1][1]+c[i]
    else:
        if(b[i]>a[i]):
            dp[i][1]=dp[i-1][2]+b[i]
        else:
            dp[i][0]=dp[i-1][2]+a[i]
    # print(dp[i][0],dp[i][1],dp[i][2])
if(dp[n-1][0]!=0):
    print(dp[n-1][0])
elif(dp[n-1][1]!=0):
    print(dp[n-1][1])
else:
    print(dp[n-1][2])

Submission status: Wrong Answer

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

dp = [[0 for i in range(3)] for j in range(N+1)]


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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
n=input()
l1,l2,l3=[],[],[]
for i in range(n):
    a,b,c=map(int,stdin.readline().split())
    l1.append(a)
    l2.append(b)
    l3.append(c)
l4,l5,l6=[[l1[0],1]],[[l2[0],2]],[[l3[0],3]]
for i in range(1,n):
    l=[l1[i],l2[i],l3[i]]
    l.sort()
    d={l1[i]:1,l2[i]:2,l3[i]:3}
    a=max(l)
    b=min(l)
    if l.count(a)==1:
        if l.count(b)==1:
            if l4[-1][1]==d[l[2]]:
                l4.append([l[1],d[l[1]]])
            elif l4[-1][1]==0:
                l4.append([a,d[a]])
            else:
                l4.append([l[2],d[l[2]]])
            if l5[-1][1]==d[l[2]]:
                l5.append([l[1],d[l[1]]])
            elif l5[-1][1]==0:
                l5.append([a,d[a]])
            else:
                l5.append([l[2],d[l[2]]])
            if l6[-1][1]==d[l[2]]:
                l6.append([l[1],d[l[1]]])
            elif l6[-1][1]==0:
                l6.append([a,d[a]])
            else:
                l6.append([l[2],d[l[2]]])       
        else:
            if l4[-1][1]==d[l[2]]:
                l4.append([l[1],0])
            else:
                l4.append([l[2],d[l[2]]])
            if l5[-1][1]==d[l[2]]:
                l5.append([l[1],0])
            else:
                l5.append([l[2],d[l[2]]])
            if l6[-1][1]==d[l[2]]:
                l6.append([l[1],0])
            else:
                l6.append([l[2],d[l[2]]])       
    elif l.count(a)==2:
        if l4[-1][1]==d[l[2]]:
            l4.append([l[1],d[l[1]]])
        elif l4[-1][1]==0:
            l4.append([a,0])
        elif l4[-1][1]==d[l[1]]:
            l4.append([l[2],d[l[2]]])
        else:
            l4.append([l[2],0])
        if l5[-1][1]==d[l[2]]:
            l5.append([l[1],d[l[1]]])
        elif l5[-1][1]==0:
            l5.append([a,0])
        elif l4[-1][1]==d[l[1]]:
            l5.append([l[2],d[l[2]]])
        else:
            l5.append([l[2],0])
        if l6[-1][1]==d[l[2]]:
            l6.append([l[1],d[l[1]]])
        elif l6[-1][1]==0:
            l6.append([a,0])
        elif l6[-1][1]==d[l[1]]:
            l6.append([l[2],d[l[2]]])
        else:
            l6.append([l[2],0])
    else:
        l4.append([l[2],0])
        l5.append([l[2],0])
        l6.append([l[2],0])
sum1,sum2,sum3=0,0,0
for i in l4:
    sum1+=i[0]
for i in l5:
    sum2+=i[0]
for i in l6:
    sum3+=i[0]
#print l4,'\n',l5,'\n',l6
stdout.write(str(max(sum1,sum2,sum3))+'\n')

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
n=input()
l1,l2,l3=[],[],[]
for i in range(n):
    a,b,c=map(int,stdin.readline().split())
    l1.append(a)
    l2.append(b)
    l3.append(c)
l4,l5,l6=[[l1[0],1]],[[l2[0],2]],[[l3[0],3]]
for i in range(1,n):
    l=[l1[i],l2[i],l3[i]]
    l.sort()
    d={l1[i]:1,l2[i]:2,l3[i]:3}
    a=max(l)
    b=min(l)
    if l.count(a)==1:
        if l.count(b)==1:
            if l4[-1][1]==d[l[2]]:
                l4.append([l[1],d[l[1]]])
            elif l4[-1][1]==0:
                l4.append([a,d[a]])
            else:
                l4.append([l[2],d[l[2]]])
            if l5[-1][1]==d[l[2]]:
                l5.append([l[1],d[l[1]]])
            elif l5[-1][1]==0:
                l5.append([a,d[a]])
            else:
                l5.append([l[2],d[l[2]]])
            if l6[-1][1]==d[l[2]]:
                l6.append([l[1],d[l[1]]])
            elif l6[-1][1]==0:
                l6.append([a,d[a]])
            else:
                l6.append([l[2],d[l[2]]])       
        else:
            if l4[-1][1]==d[l[2]]:
                l4.append([l[1],0])
            else:
                l4.append([l[2],d[l[2]]])
            if l5[-1][1]==d[l[2]]:
                l5.append([l[1],0])
            else:
                l5.append([l[2],d[l[2]]])
            if l6[-1][1]==d[l[2]]:
                l6.append([l[1],0])
            else:
                l6.append([l[2],d[l[2]]])       
    elif l.count(a)==2:
        if l4[-1][1]==d[l[2]]:
            l4.append([l[1],d[l[1]]])
        elif l4[-1][1]==0:
            l4.append([a,d[a]])
        elif l4[-1][1]==d[l[1]]:
            l4.append([l[2],d[l[2]]])
        else:
            l4.append([l[2],0])
        if l5[-1][1]==d[l[2]]:
            l5.append([l[1],d[l[1]]])
        elif l5[-1][1]==0:
            l5.append([a,d[a]])
        elif l4[-1][1]==d[l[1]]:
            l5.append([l[2],d[l[2]]])
        else:
            l5.append([l[2],0])
        if l6[-1][1]==d[l[2]]:
            l6.append([l[1],d[l[1]]])
        elif l6[-1][1]==0:
            l6.append([a,d[a]])
        elif l6[-1][1]==d[l[1]]:
            l6.append([l[2],d[l[2]]])
        else:
            l6.append([l[2],0])
    else:
        l4.append([l[2],0])
        l5.append([l[2],0])
        l6.append([l[2],0])
sum1,sum2,sum3=0,0,0
for i in l4:
    sum1+=i[0]
for i in l5:
    sum2+=i[0]
for i in l6:
    sum3+=i[0]
#print l4,'\n',l5,'\n',l6
stdout.write(str(max(sum1,sum2,sum3))+'\n')

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = []
for i in range(n):
	aa, bb, cc = map(int, input().split())
	abc.append([aa,bb,cc])
dp = [0] * n
s = 0
lis = list(enumerate([abc[0][0],abc[0][1],abc[0][2]]))
lis = sorted(lis, key= lambda x:x[1],reverse=True)
old = 0
s = lis[0][1]
if lis[0][1] == lis[1][1]:
	old = 3
else:
	old = lis[0][0]
for i in range(1,n):
	x = 0
	y = list(enumerate([abc[i][0],abc[i][1],abc[i][2]]))
	for j, k in y:
		if j == old:
			y.pop(j)
	y = sorted(y, key= lambda x:x[1],reverse=True)
	s += y[0][1]
	if y[0][1] == y[1][1]:
		old = 3
	else:
		old = y[0][0]
	#print (s)
print (s)

Submission status: Wrong Answer

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

#print(N,A)

dp = [[0] * 3 for _ in range(N)]
dp[0][0] = A[0][0]
dp[0][1] = A[0][1]
dp[0][2] = A[0][2]
#print(dp)

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

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

Submission status: Wrong Answer

Solution code:
"""
@author:  wangquaxiu
@time:  2020/3/7 19:47
"""

import numpy as np
n = int(input())
dp = np.zeros((n,3),dtype=np.int)
happy = []
for i in range(n):
    d = list(map(int,input().split()))
    happy.append(d)

for i in range(3):
    dp[0][1] = happy[0][i]

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

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(500*500) 

N =int(input())
Hmax_a = [-1]*N #i日目の最大値
Hmax_b = [-1]*N
Hmax_c = [-1]*N
ske_a = [-1]*N #i日目に選ぶ活動は何番目か
ske_b = [-1]*N
ske_c = [-1]*N
fst_a = 0 #初日の選択
fst_b = 1
fst_c = 2

activities = []
for cmd in sys.stdin:
  abc = list(map(int, cmd.strip("/n").split()))
  activities.append(abc)

#今日まで最大に幸福。今日選んだのはどれか
#今日の最大値は
def func(N,firstact,ske,Hmax):
  for n in range(N):
    if n == 0:
      ske[0] = firstact
      Hmax[0] = activities[0][firstact]
    else:
      #昨日の活動ske[n-1]以外で、「昨日迄の最大値と今日の幸福度の和」が最大のを選ぶ  
      max = 0
      for i in range(3):
        if i == ske[n-1]:
          continue
        elif Hmax[n-1] + activities[n][i] > max:
          max = Hmax[n-1] + activities[n][i]
          max_i = i
      ske[n] = max_i
      Hmax[n] = Hmax[n-1] + activities[n][max_i]
  return Hmax[N-1]

ans = max(func(N,fst_a,ske_a,Hmax_a),func(N,fst_b,ske_a,Hmax_b),func(N,fst_c,ske_a,Hmax_c))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N =int(input())
Hmax_a = [-1]*N #i日目の最大値
Hmax_b = [-1]*N
Hmax_c = [-1]*N
ske_a = [-1]*N #i日目に選ぶ活動は何番目か
ske_b = [-1]*N
ske_c = [-1]*N
fst_a = 0 #初日の選択
fst_b = 1
fst_c = 2

activities = []
for cmd in sys.stdin:
  abc = list(map(int, cmd.strip("/n").split()))
  activities.append(abc)

#今日まで最大に幸福。今日選んだのはどれか
#今日の最大値は
def func(N,firstact,ske,Hmax):
  for n in range(N):
    if n == 0:
      ske[0] = firstact
      Hmax[0] = activities[0][firstact]
    else:
      #昨日の活動ske[n-1]以外で、「昨日迄の最大値と今日の幸福度の和」が最大のを選ぶ  
      max = 0
      for i in range(3):
        if i == ske[n-1]:
          continue
        elif Hmax[n-1] + activities[n][i] > max:
          max = Hmax[n-1] + activities[n][i]
          max_i = i
      ske[n] = max_i
      Hmax[n] = Hmax[n-1] + activities[n][max_i]
  return Hmax[N-1]

ans = max(func(N,fst_a,ske_a,Hmax_a),func(N,fst_b,ske_a,Hmax_b),func(N,fst_c,ske_a,Hmax_c))
print(ans)

Submission status: Wrong Answer

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

dp = [(None, 0) for _ in range(N)]
for i,v in enumerate(Q[0]):
    if v>dp[0][1]:
        dp[0] = (i, v)
for i in range(1, N):
    for j, v in enumerate(Q[i]):
        if j!=dp[i-1][0] and dp[i][1]<v+dp[i-1][1]:
            dp[i] = (j, v+dp[i-1][1])
print(dp[-1][1])

Submission status: Wrong Answer

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

dp = [(0, 0) for _ in range(N)]
for i,v in enumerate(Q[0]):
    if v>dp[0][1]:
        dp[0] = (i, v)
    
for i in range(1, N):
    for j, v in enumerate(Q[i]):
        if j!=dp[i-1][0] and dp[i][1]<v+dp[i-1][1]:
            dp[i] = (j, v+dp[i-1][1])
print(dp[-1][1])

Submission status: Wrong Answer

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

dp = [(0, 0) for _ in range(N)]
for i,v in enumerate(Q[0]):
    if v>dp[0][1]:
        dp[0] = (i, v)
    
for i in range(1, N):
    for j, v in enumerate(Q[i]):
        if j!=dp[i-1][0] and dp[i][1]<v:
            dp[i] = (j, v+dp[i-1][1])
print(dp[-1][1])

Submission status: Wrong Answer

Solution code:
inf = 10 ** 9 + 7

n = int(input())

happiness = [tuple(map(int, input().split())) for _ in range(n)]
dp = [[inf]*3 for _ in range(n)]

dp[0][0] = happiness[0][0]
dp[0][1] = happiness[0][1]
dp[0][2] = happiness[0][2]

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = []
for _ in range(n):
    abc_ = list(map(int, input().split()))
    abc.append(abc_)
dp = [[0]*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(abc[i][1]+dp[i-1][0], abc[i][2]+dp[i-1][0])
    dp[i][1] = max(abc[i][0]+dp[i-1][1], abc[i][2]+dp[i-1][1])
    dp[i][2] = max(abc[i][0]+dp[i-1][2], abc[i][1]+dp[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())
l=[]
for i in range(N):
  L=list(map(int,input().split()))
  l.append(L)
dp = [max(l[0]) for i in range(N)]
check = [[] for i in range(N)]
for i in range(3):
  if l[0][i] == max(l[0]):
    check[0].append(i)
if N >= 2:
  for i in range(3):
    for j in range(3):
      if i != j:
        dp[1] = max(dp[1], l[0][i] + l[1][j])
  for i in range(3):
    for j in range(3):
      if i != j and dp[1] == l[0][i] + l[1][j]:
        check[1].append(j)
if N >= 3:
  for i in range(2,N):
    for j in range(3):
      for k in range(3):
        if j != k and j not in check[i-2]:
          dp[i] = max(dp[i], dp[i-2] + l[i-1][j] + l[i][k])
    for j in range(3):
      for k in range(3):
        if j != k and j not in check[i-2] and dp[i] == dp[i-2] + l[i-1][j] + l[i][k]:
          check[i].append(k) 
print(dp[N-1])

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())

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

dp[0][0], dp[0][1], dp[0][2] = map(int, sys.stdin.readline().split())

tmp = [0, 0, 0]

for i in range(1, N):
    tmp[0], tmp[1], tmp[2] = map(int, sys.stdin.readline().split())
    for j in range(3):
        dp[i][j] = max(dp[i-1][(j+1)%3]+tmp[(j+2)%3], dp[i-1][(j+2)%3]+tmp[(j+2)%3])

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

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


def main(N, DATA):
    dp = [[0 for _ in range(N)] for _ 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] + DATA[i][k])

    res = 0

    for v in range(N):
        res = max(res, dp[N][v])
    print(res)


if __name__ == '__main__':
    # N = int(input())
    # DATA = [input().split() for _ in range(N)]
    N = 3
    DATA = [
        [10, 40, 70],
        [20, 50, 80],
        [30, 60, 90]
    ]
    main(N, DATA)

Submission status: Wrong Answer

Solution code:
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    h = [[0] * 3 for _ in range(n)]

    for i in range(n):
        h[i] = list(map(int,ipti().split()))

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

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
ABC=[]
for i in range(N):
  l=list(map(int,input().split()))
  ABC=ABC+[l]
dp=[[0,0,0]]*N#dp[i][j]はi+1日目にアクティビティjを選んだ時の活動終了時の幸福量
for i in range(3):
  dp[0][i]=ABC[0][i]
for i in range(1,N):
  dp[i][1]=max(dp[i-1][2]+ABC[i][1],dp[i-1][0]+ABC[i][1])
  dp[i][0]=max(dp[i-1][1]+ABC[i][0],dp[i-1][2]+ABC[i][0])
  dp[i][2]=max(dp[i-1][1]+ABC[i][2],dp[i-1][0]+ABC[i][2])
ans=max(dp[N-1])
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())

    table = []
    for _ in range(n):
        table.append([int(v) for v in input().split()])

    dp = [0] * 3

    for i in range(n):
        dp_n = [0] * 3

        a, b, c = table[i]

        a0 = dp[0]
        b0 = dp[1]
        c0 = dp[2]

        dp_n[0] = max(b0, c0) + a
        dp_n[1] = max(c0, a0) + b
        dp_n[2] = max(a0, b0) + c

        dp = dp_n

    print(max(dp))

Submission status: Wrong Answer

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)

INF = 1 << 60

# ここから書き始める
n = int(input())
x = [[int(j) for j in input().split()] for i in range(n)]
# print(x)
dp = [-INF] * n
dp[0] = max(x[0])
index = x[0].index(dp[0])
# print(index)
for i in range(1, n):
    a = []
    for j in range(3):
        if j != index:
            a.append(x[i][j])
    dp[i] = max(dp[i], dp[i - 1] + max(a))
    index = x[i].index(max(a))
# print(dp)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
h_list = []
for i in range(N):
    h_list.append([i for i in map(int,input().split())])

print(h_list)

dp = np.zeros((N,3))
dp[0] = h_list[0]
for i in range(1,N):
    dp[i,0] = max(dp[i-1,1], dp[i-1,2]) + h_list[i][0]
    dp[i,1] = max(dp[i-1,0], dp[i-1,2]) + h_list[i][1]
    dp[i,2] = max(dp[i-1,0], dp[i-1,1]) + h_list[i][2]

print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
n=int(input())

ab = []
for _ in range(n):
    a, b, c = (int(x) for x in input().split())
    ab.append([a, b, c])

dp = [0]*n
memo = -1
memos = -1

for i in range(n):
    for j in range(3):
        if i == 0:
            dp[i] = max(ab[0])
            memos = j
        elif memo != j and dp[i] < dp[i-1]+ab[i][j]:
            dp[i] = dp[i-1]+ab[i][j]
            memos = j
    memo = memos
print(dp)

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)]

for i, a in enumerate(a):
  dp_1 = dp[i-1]
  dp[i][0] = max(dp_1[1], dp_1[2]) + a[0]
  dp[i][1] = max(dp_1[0], dp_1[2]) + a[1]
  dp[i][2] = max(dp_1[0], dp_1[1]) + a[2]

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

Submission status: Wrong Answer

Solution code:

n = int(input())
abc = []
dp = [[0 for i in range(2)]for j in range(n)]
for i in range(n):
    abc.append(list(map(int,input().split())))
dp [0][0] = max(abc[0])
dp [0][1] = int(abc[0].index(max(abc[0])))
for i in range(n):
    if i+1 < n:
        act = dp[i][1]
        abc[i+1][act] = 0
        dp[i+1][0] = max(dp[i+1][0],dp[i][0]+max(abc[i+1]))
        dp[i+1][1] = abc[i+1].index(dp[i+1][0]-dp[i][0])
print(dp[-1][0])

Submission status: Wrong Answer

Solution code:
N  = int(input())

plans = []

for _ in range(N):
  a, b, c = map(int, input().split())
  plans.append((a, b, c))
  
memo = [[0] * (N + 1) for _ in range(3)]

for day, plan in enumerate(plans, 1):
  memo[0][day] = max(memo[1][day - 1], memo[2][day - 1]) + plan[0]
  memo[1][day] = max(memo[0][day - 1], memo[2][day - 1]) + plan[1]
  memo[2][day] = max(memo[0][day - 1], memo[1][day - 1]) + plan[2]
    
print(max(memo[0][N], memo[1][N], memo[1][N]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    a = [0] * N
    b = [0] * N
    c = [0] * N

    for i in range(N):
        a_i, b_i, c_i = list(map(int, input().split()))
        a[i] = a_i
        b[i] = b_i
        c[i] = c_i

    # print(a, b, c)

    dp_value = [0 for _ in range(N)]
    dp_action = [None for _ in range(N)]

    for action, v in zip(['A', 'B', 'C'], [a[0], b[0], c[0]]):
        if v > dp_value[0]:
            dp_value[0] = v
            dp_action[0] = action

    for i in range(1, N):
        for action, val in zip(['A', 'B', 'C'], [a[i], b[i], c[i]]):
            if dp_action[i - 1] == action:
                continue

            total = dp_value[i-1] + val

            if total > dp_value[i]:
                dp_value[i] = total
                dp_action[i] = action

    print(dp_value[-1])


if __name__ == '__main__':
    main()

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)

dp = [0]*(n+1)

x, y, z = 1, 1, 1

for i in range(n):
    m = 0
    _a, _b, _c = a[i]*x, b[i]*y, c[i]*z
    if _b <= _a and _c <= _a:
        m = _a
        x, y, z = 0, 1, 1
    elif _a <= _b and _c <= _b:
        m = _b
        x, y, z = 1, 0, 1
    else:
        m = _c
        x, y, z = 1, 1, 0

    dp[i+1] = dp[i] + m

print(dp[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] * n
for x in range(n):
    a[x] = list(map(int, input().split()))
print(a)
dp = [[0 for _ in range(3)] for _ in range(n+1)]
print(dp)
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:
import sys
input = sys.stdin.readline
import numpy as np

def main():
    N = int(input())
    act = np.array([[int(item) for item in input().split()] for _ in range(N)])

    dp = np.zeros((2, 3), dtype='int64')
    selector = np.array([[0,1,1], [1,0,1], [1,1,0]])

    for i in range(0,N):
        print(dp[i%2]*selector)
        print(np.max(dp[i%2]*selector, axis=1))
        dp[i%2^1] = np.max(dp[i%2]*selector, axis=1) + act[i]
        print(dp)

    print(max(dp[N%2]))

main()

Submission status: Wrong Answer

Solution code:
N = 3
A=[[10, 40, 70], [20, 50, 80], [30, 60, 90]]
dp = [[0] * 3 for _ in range(N)]  # 初期化
dp[0] = A[0]  # 初期化
print(dp[0])
for i in range(N-1):
    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(max(dp[N-1]))
print((dp[N-1]))
print(max(dp[N-2]))
print((dp[N-2]))
print(max(dp[N-3]))
print((dp[N-3]))

Submission status: Wrong Answer

Solution code:
N = int(input())

what_to_do = []
for i in range(N):
    input2 = input().split()
    tmp1,tmp2,tmp3 = list(map(int,input2))
    what_to_do.append([tmp1,tmp2,tmp3])
    
print(what_to_do)

dp = []
for _ in range(N+1):
    dp.append([0,0,0])

print(dp)

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = [Scanner.map_int() for _ in range(N)]
    dp = [[0 for _ in range(3)] for _ in range(N)]
    dp[0][0], dp[0][1], dp[0][2] = A[0]
    print(dp)
    for i in range(1, N):
        for c in range(3):
            dp[i][c] = max(dp[i][c], dp[i-1][(c+1) % 3] + A[i][c])
            dp[i][c] = max(dp[i][c], dp[i-1][(c+2) % 3] + A[i][c])
    print(max(dp[N-1]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#便利そうなので置いとく
import fractions 
import functools 
#再帰関数を使うときは、再帰上限を上げておこうね！
import sys
sys.setrecursionlimit(200000000)
# my functions here!
def pin(type=int):
    return map(type,input().split())
"""
------------------------------------------------------------------
|OBJECTIVE:                                                      |
|Educatinal DP contest("https://atcoder.jp/contests/dp")を解こう!|
------------------------------------------------------------------
"""
#solution:
INF = float("inf")
"""
|#遷移式を考える
|   つまり、漸化式みたいに i回目までの結果を保存して、i+1回目の評価を行う
"""
def Flog_1(N,H):
    dp=[INF for i in range(N)]#{DP table}:最小化問題なので初期値はINF, h1=H[0]）
    dp[0]=0  #h1=0
    dp[1]=abs(H[1]-H[0])#ほら、"2段前"がないから…
    for i in range(2,N):
        hop1=dp[i-1]+abs(H[i-1]-H[i]) 
        hop2=dp[i-2]+abs(H[i-2]-H[i]) 
        #print(hop1,hop2)
        dp[i]=hop1 if hop1<hop2 else hop2
    return dp
def Flog_1_Another(N,H):#"配る"DP
    dp=[INF for i in range(N)]#{DP table}:最小化問題なので初期値はINF, h1=H[0]）
    dp[0]=0  #h1=0
    for i in range(0,N):
        for k in [1,2]:
            if i+k <N:
                dp[i+k]=min(dp[i+k],dp[i]+abs(H[i+k]-H[i]))
    return dp
"""
|# Flog1との違い:飛ぶ段数に（1個か2個という）制限がない
|    
"""    
def Flog_2(N,K,H):#pypy回答でなんとかおｋ
    dp=[INF for i in range(N)]#{DP table}:最小化問題なので初期値はINF, h1=H[0]）
    dp[0]=0  #h1=0,default position
    for i in range(1,N):#k段前から飛んでくることを考えよ
        temp = INF
        for k in range(1,K+1):
            if i-k < 0:break
            else:
                #print("*",i-k)
                temp = min(temp,(dp[i-k]+abs(H[i-k]-H[i])))
                
        dp[i]=temp
        #print("*",dp)
    return dp
def Flog_2_Another(N,K,H):#"配る"DP
    dp=[INF for i in range(N)]#{DP table}:最小化問題なので初期値はINF, h1=H[0]）
    dp[0]=0  #h1=0
    for i in range(0,N):
        for k in range(1,K+1):
            if i+k <N:
                dp[i+k]=min(dp[i+k],dp[i]+abs(H[i+k]-H[i]))
    return dp
def Flog_2_YETAnother(N,K,H):#python提出やりたい再帰関数やりたいよお
    #つまり、つまりf2Y(N,K,H)->f2Y((0 or enough value to be default),K,H)に持っていく関数を書くぞ
    if N == 1:
        return 0
    else:
        map(min,[Flog_2_YETAnother(N-i,K,H) for i in range(1,N+1)])
    #詰んだ

def vacation(N):
    #これは二次元で書けばいいですね？
    dp=[[0]*3 for i in range(N)]#[i]+1日目にある行動をした時にできる幸福度の最大値 
    dp[0]=list(pin())
    #print(dp[0])
    for i in range(1,N):
        #めんどいのでfor分かかない、ごめんね
        temp=list(pin())
        print("*",temp)
        dp[i][0]= max(dp[i-1][1],dp[i-1][2])+temp[0]
        dp[i][1]= max(dp[i-1][2],dp[i-1][0])+temp[1]
        dp[i][2]= max(dp[i-1][0],dp[i-1][1])+temp[2]
        #print(max(dp[i-1][2],dp[i-1][0]),temp[1])
        #print(dp[i])
    return max(dp[-1])
#input
N,=pin()

#output
print(vacation(N))