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:
def pin(type=int):
    return map(type,input().split())
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))

Submission status: Wrong Answer

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

da, db, dc = 0, 0, 0

for a, b, c in abc:
    na = max(db, dc) + a
    nb = max(da, dc) + a
    nc = max(da, db) + a
    da = na
    db = nb
    dc = nc
    
print(max([na, nb, nc]))

Submission status: Wrong Answer

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

dp = [[0]*3]*N
dp[0] = A[0]

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

Submission status: Wrong Answer

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

dp = [[0]*3]*N
dp[0] = A[0]

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

Submission status: Wrong Answer

Solution code:
n, *t = map( int, open( 0 ).read().split() )

# manemane
A, B, C = 0, 0, 0
for i in  range( n ):
  A, B, C = t[ 3 * i  ] + max( B, A ), t[ 3 * i + 1 ] + max( A, C ), t[ 3 * i + 2 ] + max( A, B )

print( max( A, B, C ) )

Submission status: Wrong Answer

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

for _ in range(n):
  d.append(list(map(int, input().split())))
  
dp = [0] * (n+1)
dps = [5] * (n+1)

for i in range(n):  
  tdp = 0
  tdps = 5
  for j in range(3):
    if tdp < d[i][j]:
      if i == 0 or j != dps[i-1]:
        tdp = d[i][j]
        tdps = j
  dp[i] = tdp
  dps[i] = tdps
  
print(sum(dp))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline  #文字列入力では注意！

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline  #文字列入力では注意！

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

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)
print(A,B,C)
dp = [[0]*3 for i in range(n+1)]
for i in range(n):
    dp[i+1][0] = max(max( dp[i][1], dp[i][2] ) + A[i] ,dp[i+1][0])
    dp[i+1][1] = max(max( dp[i][0], dp[i][2] ) + B[i] ,dp[i+1][1])
    dp[i+1][2] = max(max( dp[i][0], dp[i][1] ) + C[i] ,dp[i+1][2])
    
print(max(dp[-1]))

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)
print(A,B,C)
dp = [[0]*3 for i in range(n+1)]
for i in range(n):
    dp[i+1][0] = max(max( dp[i][1], dp[i][2] ) + A[i] ,dp[i+1][0])
    dp[i+1][1] = max(max( dp[i][0], dp[i][2] ) + B[i] ,dp[i+1][1])
    dp[i+1][2] = max(max( dp[i][0], dp[i][1] ) + C[i] ,dp[i+1][2])
    print(dp)
print(max(dp[-1]))

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

Solution code:
def chmin(a, b):
  if (a > b):
    return b

  return a

def chmax(a, b):
  if (a < b):
    return b

  return a

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

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

for n in range(N):
  for j in range(0, 3):
    for k in range(0, 3):
      if n == 0:
        dp[0][0] = li[0][0]
        dp[0][1] = li[0][1]
        dp[0][2] = li[0][2]
        continue
      
      if j == k:
        continue

      dp[n][j] = chmax(dp[n][j], dp[n-1][j] + li[n][k])

print(dp)

Submission status: Wrong Answer

Solution code:
def chmin(a, b):
  if (a > b):
    return b

  return a

def chmax(a, b):
  if (a < b):
    return b

  return a

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

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

for n in range(N):
  for j in range(0, 3):
    for k in range(0, 3):
      if n == 0:
        dp[0][0] = li[0][0]
        dp[0][1] = li[0][1]
        dp[0][2] = li[0][2]
        continue
      
      if j == k:
        continue

      dp[n][k] = chmax(dp[n-1][k], dp[n-1][j] + li[n][k])

print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
def chmin(a, b):
  if (a > b):
    return b

  return a

def chmax(a, b):
  if (a < b):
    return b

  return a

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

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

for n in range(N):
  for j in range(0, 3):
    for k in range(0, 3):
      if j == k:
        continue

      dp[n][k] = chmax(dp[n-1][k], dp[n-1][j] + li[n][k])

print(max(dp[-1]))

Submission status: Wrong Answer

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

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

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


print(max(dp[n]))

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
import sys 
sys.setrecursionlimit(2147483647)

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

#@lru_cache(None)
def dfs(d,pre):
    if (d,pre) in dic: return dic[(d,pre)]
    if d>=N - 1:
        dic[(d,pre)] = 0 
        return 0
    ma = 0 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,idx) + a 
            ma = max(res,ma)
    dic[(d,pre)] = ma
    return dic[(d,pre)]
dic = {}
res = dfs(-1,-1)
print(res)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
import sys 
sys.setrecursionlimit(2147483647)

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

#@lru_cache(None)
def dfs(d,pre):
    if (d,pre) in dic: return dic[(d,pre)]
    if d>=N-1:
        dic[(d,pre)] = 0
        return 0
    ma = 0 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,idx) + a 
            ma = max(res,ma)
    dic[(d,pre)] = ma
    return ma
dic = {}
res = dfs(-1,-1)
print(res)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
import sys 
sys.setrecursionlimit(2147483647)

N = int(input())
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))


#@lru_cache(None)
def dfs(d,pre):
    if (d,pre) in dic: return dic[(d,pre)]
    if d>=N-1: return 0
    ma = 0 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,idx) + a 
            ma = max(res,ma)
    dic[(d,pre)] = ma
    return ma
dic = {}
res = dfs(-1,-1)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #整数1つinput
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii())
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #文字列1つinput
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

n = ii()
arr = llint(n)
dp = [[0]*3 for _ in range(n)]
dp[0][0],dp[0][1],dp[0][2]=arr[0][0],arr[0][1],arr[0][2]
for i in range(1,n):
    for abc in [0,1,2]:
        if abc==0:
            dp[i][0] = max(arr[i][1]+dp[i-1][1],arr[i][2]+dp[i-1][2])
        elif abc==1:
            dp[i][1] = max(arr[i][0]+dp[i-1][0],arr[i][2]+dp[i-1][2])
        else:
            dp[i][2] = max(arr[i][1]+dp[i-1][1],arr[i][0]+dp[i-1][0])

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
def fnSolv():
  iNum = int(input())
  naABC = np.zeros((iNum, 3), dtype = int)
  naDP  = [0]*3
  #naDP  = [10**9, 10**9, 10**9]
  for iI in range(iNum):
    naABC[iI] = list(map(int, input().split()))
  for iA, iB, iC in naABC:
    naDPa = max([naDP[1] + iA, naDP[2] + iA])
    naDPb = max([naDP[2] + iB, naDP[0] + iB])
    naDPc = max([naDP[0] + iC, naDP[1] + iC])
    naDP = [naDPa, naDPb, naDPc]
    print(naDP)
  print(max(naDP))

if __name__ == '__main__':
  fnSolv()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

def max_happiness(n, data, dp, a, b, c):
  if dp[n] is not None:
    return dp[n]
  if n == 0:
    if a and b:
      return max(data[n][0], data[n][1])
    elif b and c:
      return max(data[n][1], data[n][2])
    elif c and a:
      return max(data[n][2], data[n][0])

  max_a = -1
  max_b = -1
  max_c = -1

  if a:
    max_a = data[n][0] + max_happiness(n-1, data, dp, a=False, b=True, c=True)
  if b:
    max_b = data[n][1] + max_happiness(n-1, data, dp, a=True, b=False, c=True)
  if c:
    max_c = data[n][2] + max_happiness(n-1, data, dp, a=True, b=True, c=False)

  dp[n] = max(max_a, max_b, max_c)
  return dp[n]

N = int(input())
data = []
dp = [None]*N
for _ in range(N):
  data.append([int(num) for num in input().split()])

print(max_happiness(N-1, data, dp, a=True, b=True, c=True))

Submission status: Wrong Answer

Solution code:
N=int(input())

DP=[0]*N

h = list(map(int, input().split()))
DP[0] = max(h)
pidx = h.index(max(h))

for i in range(1,N):
    h=list(map(int,input().split()))
    h[pidx]=0
    DP[i]=DP[i-1]+max(h)
    pidx=h.index(max(h))

print(DP[N-1])

Submission status: Wrong Answer

Solution code:
def chmax(x, y, ys):
  if x>y:
    return x, (ys+1)%3
  elif x<y:
    return y, (ys+2)%3
  else:
    return x, -1
def chmax3(x, y, z):
  ans = max(x, y, z)
  ind = [i for i, a in enumerate([x,y,z]) if a==ans]
  if len(ind)==1:
    return ans, ind[0]
  else:
    return ans, -1

N, *hp = map(int, open(0).read().split())
dp = [0]*3
for i in range(3):
  dp[i] = hp[i]
  ys = i
  for j in range(1,N):
    tp = 3*j
    if ys==-1:
      tpmax, ys = chmax3(hp[tp], hp[tp+1], hp[tp+2])
    else:
      tpmax, ys = chmax(hp[tp+(ys+1)%3], hp[tp+(ys+2)%3], ys)
    dp[i] += tpmax
print(max(dp))

Submission status: Wrong Answer

Solution code:
N = int(input())

a  = [0] * N
b  = [0] * N
c  = [0] * N

def calc_next_dp(start):

    dp = [0] * N
    dp[0] = start;

    for i in range(N-1):
        if(dp[i] == a[i]):
#            print("a")
            dp[i+1] = max(b[i+1], c[i+1])
        elif(dp[i] == b[i]):
#            print("b")
            dp[i+1] = max(c[i+1], a[i+1])
        elif(dp[i] == c[i]):
#            print("c")
            dp[i+1] = max(a[i+1], b[i+1])
#        else:
#            print("error!");

    return sum(dp)


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

#print(max(list(map(calc_next_dp, [a[0], b[0], c[0]]))))


print(max(calc_next_dp(a[0]), calc_next_dp(b[0]),calc_next_dp(c[0])))

Submission status: Wrong Answer

Solution code:
N = int(input())

a  = [0] * N
b  = [0] * N
c  = [0] * N

def calc_next_dp(start):

    dp = [0] * N
    dp[0] = start;

    for i in range(N-1):
        if(dp[i] == a[i]):
#            print("a")
            dp[i+1] = max(b[i+1], c[i+1])
        elif(dp[i] == b[i]):
#            print("b")
            dp[i+1] = max(c[i+1], a[i+1])
        elif(dp[i] == c[i]):
#            print("c")
            dp[i+1] = max(a[i+1], b[i+1])
#        else:
#            print("error!");

    return sum(dp)


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

print(max(list(map(calc_next_dp, [a[0], b[0], c[0]]))))

Submission status: Wrong Answer

Solution code:
N = int(input())

a  = [0] * N
b  = [0] * N
c  = [0] * N

def calc_next_dp(start):

    dp = [0] * N
    dp[0] = start;

    for i in range(N-1):
        if(dp[i] == a[i]):
            dp[i+1] = max(b[i+1], c[i+1])
        elif(dp[i] == b[i]):
            dp[i+1] = max(c[i+1], a[i+1])
        elif(dp[i] == c[i]):
            dp[i+1] = max(a[i+1], b[i+1])
        else:
            print("error!");

    return sum(dp)


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

print(max(list(map(calc_next_dp, [a[0], b[0], c[0]]))))

Submission status: Wrong Answer

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

def chmax(a, b):
    if a > b:
        return a
    else:
        return b

dp = [[ 0 for _ in range(3)]for _ in range(n+10)]

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

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

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

Submission status: Wrong Answer

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

def chmax(a, b):
    if a > b:
        return a
    else:
        return b

dp = [[ 0 for _ in range(3)]for _ in range(n+10)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            else:
                dp[i][j] = chmax(dp[i+1][k], dp[i][j]+A[i][k])

res = 0
for i in range(3):
    res = chmax(res, dp[n][i])
print(res)

Submission status: Wrong Answer

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

def chmax(a, b):
    if a > b:
        return a
    else:
        return b

dp = [[ 0 for _ in range(3)]for _ in range(n+10)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            else:
                dp[i][k] = chmax(dp[i+1][k], dp[i][j]+A[i][k])

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

Submission status: Wrong Answer

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

for i in range(n):
  abc[i] = list(map(int,input().split()))
  
for i in range(3):
  dp[i][0] = abc[0][i]

for i in range(n):
  for j in range(3):    
    for k in range(3):
      if j==k:
        pass
      else:
        dp[j][i] = max(dp[j][i], dp[k][i-1]+abc[i][j])
        
print(max([row[-1] for row in dp]))

Submission status: Wrong Answer

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

import numpy as np

EDPC = "https://atcoder.jp/contests/dp/"
TDPC = "https://atcoder.jp/contests/tdpc/tasks"

############### TESTCASE ###############
test = ""

"""
3
10 40 70
20 50 80
30 60 90
ans 210
"""

"""
1
100 10 1
ans 100
"""
test = \
"""
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
ans 46
8, 8, 5, 8, 8, 4, 7 -> 48
8, 8, 5, 7, 8, 3, 7 -> 46
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################  
n = int(input2())
a = np.array([list(map(int, input2().split())) for i in range(n)])  
########## Non_Numpy_solution ##########

arr = a
dp = [[0, 0, 0] for _ in range(n)]
dp[0] = arr[0]
for i in range(1, n):
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + arr[i][0]
    dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + arr[i][1]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + arr[i][2]
print (max(dp[-1]))

Submission status: Wrong Answer

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

import numpy as np

EDPC = "https://atcoder.jp/contests/dp/"
TDPC = "https://atcoder.jp/contests/tdpc/tasks"

################ DANGER ################
test = ""
#test = \
"""
3
10 40 70
20 50 80
30 60 90
ans 210
"""

"""
1
100 10 1
ans 100
"""

"""
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
ans 46
8, 8, 5, 8, 8, 4, 7 -> 48
8, 8, 5, 7, 8, 3, 7 -> 46
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################  
n = int(input2())
a = np.array([list(map(int, input2().split())) for i 
              in range(n)], dtype="uint16")  
############ Numpy_solution ############


    
    
    
########## Non_Numpy_solution ##########
arr = a
dp = [[0, 0, 0] for _ in range(n)]
dp[0] = arr[0]
for i in range(1, n):
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + arr[i][0]
    dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + arr[i][1]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + arr[i][2]
print (max(dp[-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
values = list()
for _ in range(n):
    values.append(list(map(int, input().split())))
dp = [max(values[0])]
abc = ''
if max(values[0]) == values[0][0]:
    abc += 'a'
elif max(values[0]) == values[0][1]:
    abc += 'b'
else:
    abc += 'c'
for t in range(1, n):
    if abc[-1] == 'a':
        dp.append(dp[-1] + max(values[t][1], values[t][2]))
        if max(values[t][1], values[t][2]) == values[t][1]:
            abc += 'b'
        else:
            abc += 'c'
    elif abc[-1] == 'b':
        dp.append(dp[-1] + max(values[t][0], values[t][2]))
        if max(values[t][0], values[t][2]) == values[t][0]:
            abc += 'a'
        else:
            abc += 'c'
    else:
        dp.append(dp[-1] + max(values[t][0], values[t][1]))
        if max(values[t][0], values[t][1]) == values[t][0]:
            abc += 'a'
        else:
            abc += 'b'
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
stack=[100,200]
lista=['a','b','c']
zb=0
for i in range(n):
      
      dani=list(map(int,input().split()))
      najveca=max(dani)
      indeks_najvece=dani.index(najveca)
      if indeks_najvece==stack[len(stack)-1]:
            dani[indeks_najvece]=0
            najveca=max(dani)
            indeks_najvece=dani.index(najveca)            
            stack.append(indeks_najvece)
            zb+=najveca
      else:
            zb+=najveca            
            stack.append(indeks_najvece)      
print(zb)

Submission status: Wrong Answer

Solution code:
n=int(input())
stack=[100,200]
lista=['a','b','c']
zb=0
for i in range(n):
      
      dani=list(map(int,input().split()))
      najveca=max(dani)
      indeks_najvece=dani.index(najveca)
      if indeks_najvece==stack[len(stack)-1]:
            dani[indeks_najvece]=0
            najveca=max(dani)
            indeks_najvece=dani.index(najveca)
            stack.pop()
            stack.append(indeks_najvece)
            zb+=najveca
      else:
            zb+=najveca
            stack.pop()
            stack.append(indeks_najvece)      
print(zb)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    dp = [[0] * 3 for _ in range(N+1)]
    for i in range(1, N+1):
        # i 日目の行動による幸福度
        happiness = [int(i) for i in input().split()]
        # i-1 日目の行動
        for j in range(3):
            # i 日目の行動
            for k in range(3):
                # i日目とi-1日目の行動が同じ場合はスキップ
                if j == k:
                    continue
                # i日目に行動kを選んだときの最大値
                dp[i][k] = max(dp[i][k], dp[i-1][j] + happiness[k])
    ans = dp[-1]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    dp = [[0] * 3 for _ in range(N+1)]
    for i in range(1, N+1):
        # i 日目の行動による幸福度
        happiness = [int(i) for i in input().split()]
        # i-1 日目の行動
        for j in range(3):
            # i 日目の行動
            for k in range(3):
                # i日目とi-1日目の行動が同じ場合はスキップ
                if j == k:
                    continue
                # i日目に行動kを選んだときの最大値
                dp[i][k] = max(dp[i][k], dp[i-1][j] + happiness[k])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# 前日の行動と、当日の行動から最大値を求める。


N = int(input())
dp = [[0, 0, 0] for i in range(N)]
H = []


for i in range(N):
    l = list(map(int, input().split()))
    H.append(l)

dp[0] = [H[0][0], H[0][1], H[0][2]]

for i in range(1, N):
    # 現在の選択肢
    for k in range(3):
        # 過去の選択肢
        for j in range(3):
            if j == k:
                continue
            else:
                dp[i][j] = max(dp[i][j], (dp[i - 1][k] + H[i][j]))
    print(dp)
print(max(dp[N - 1]))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

n = int(input())
days = []
for _ in range(n):
    day = list(map(int, input().split()))
    days.append(day)
dp = [[10000] * 3] * n
# 1日目
dp[0][0] = days[0][0]
dp[0][1] = days[0][1]
dp[0][2] = days[0][2]
for d in range(1,n):
    for i in range(3):
        mx = 0
        for j in range(3):
            if i != j:
                mx = max(dp[d-1][i] + days[d][j],mx)
        dp[d][i] = mx
print(max(dp[n-1]))

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 = [[0,0,0] for i in range(N)]
dp[0] = [L[0][0],L[0][1],L[0][2]]

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

Submission status: Wrong Answer

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

ans = 0
pre = -1

ans = max(abc[0])
preIndex = abc[0].index(max(abc[0]))

for i in range(1, n):
    tmp = max(abc[i])
    tmpIndex = abc[i].index(max(abc[i]))
    if tmpIndex != preIndex:
        ans += tmp
        preIndex = tmpIndex
    else:
        ans += sorted(abc[i])[1]
        preIndex = abc[i].index(sorted(abc[i])[1])

print(ans)

Submission status: Wrong Answer

Solution code:
def main():

    def choose_max(a, b, c):
        if a >= b and a >= c:
            return (True, False, False, a)
        if b >= a and b >= c:
            return (False, True, False, b)
        return (False, False, True, c)

    n = int(input())
    activities = [[int(x) for x in input().split()] for _ in range(n)]
    dp = [0] * n
    used_a, used_b, used_c, dp[0] = choose_max(activities[0][0], activities[0][1], activities[0][2])
    for i in range(1, n):
        a, b, c = 0, 0, 0
        if not used_a:
            a = activities[i][0]
        if not used_b:
            b = activities[i][1]
        if not used_c:
            c = activities[i][2]
        used_a, used_b, used_c, selected = choose_max(a, b, c)
        dp[i] = dp[i - 1] + selected
    print(dp[n-1])


main()

Submission status: Wrong Answer

Solution code:
def main():

    def choose_max(a, b, c):
        if a >= b and a >= c:
            return (True, False, False, a)
        if b >= a and b >= c:
            return (False, True, False, b)
        return (False, False, True, c)

    n = int(input())
    activities = [[int(x) for x in input().split()] for _ in range(n)]
    dp = [0] * n
    used_a, used_b, used_c = False, False, False

    for i in range(n):
        a, b, c = 0, 0, 0
        if not used_a:
            a = activities[i][0]
        if not used_b:
            b = activities[i][1]
        if not used_c:
            c = activities[i][2]
        used_a, used_b, used_c, selected = choose_max(a, b, c)
        dp[i] = selected if i == 0 else dp[i - 1] + selected
    print(dp[n-1])


main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    activities = [[int(x) for x in input().split()] for _ in range(n)]
    dp = [0] * n
    used_a, used_b, used_c = False, False, False
    for i in range(n):
        a, b, c, selected = 0, 0, 0, 0
        if not used_a:
            a = activities[i][0]
        if not used_b:
            b = activities[i][1]
        if not used_c:
            c = activities[i][2]
        if a >= b and a >= c:
            used_a, used_b, used_c = True, False, False
            selected = a
        elif b >= a and b >= c:
            used_b, used_a, used_c = True, False, False
            selected = b
        elif c >= a and c >= b:
            used_c, used_a, used_b = True, False, False
            selected = c
        dp[i] = selected if i == 0 else dp[i - 1] + selected
    print(dp[n-1])


main()

Submission status: Wrong Answer

Solution code:
N = int(input())
DP= [0] * N
abc = [0] * N
L = list(map(int,input().split()))
maxa = max(L)
point = L.index(maxa)
DP[0] = maxa
abc[0] = point
for i in range(1,N):
    L = list(map(int,input().split()))
    for j,value in enumerate(L):
        if abc[i-1] != j:
            if DP[i] < DP[i-1] + value:
                DP[i] = DP[i-1] + value
                abc[i] = j
print(DP[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
DP= [0] * N
abc = [0] * N
L = list(map(int,input().split()))
maxa = max(L)
point = L.index(maxa)
DP[0] = maxa
abc[0] = point
for i in range(1,N):
    L = list(map(int,input().split()))
    for j in L:
        if abc[i-1] != j:
            if DP[i] < DP[i-1] + j:
                DP[i] = DP[i-1] + j
                abc[i] = j
print(DP[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
ABC = [list(map(int,input().split())) for _ in range(N)]
hap = [[0,0,0] for _ in range(N)]
hap[0] = ABC[0]
for j in range(1,N):
  for i1,i2,i3 in [[0,1,2],[1,2,0],[2,0,1]]:
    hap[j][i1] = max(hap[j-1][i2]+ABC[j][i2], hap[j-1][i3]+ABC[j][i3])
print(max(hap[-1][:]))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)

def read_input():
    lines = sys.stdin.readlines()
    n = int(lines[0])
    result = []
    for j in range(1, n+1):
        tmp = [int(x) for x in lines[j].split(" ")]
        result.append(tmp)
    return n, result

def f(cur_day=0, cur_sum=0, prev_activity=None):

    print(cur_day, [data[cur_day][k] if k!=prev_activity else -1 for k in range(3)])
    if cur_day == n-1:
        return cur_sum + max([data[n-1][k] if k!=prev_activity else -1 for k in range(3)])
    tmp = max([f(cur_day + 1, cur_sum=cur_sum + data[cur_day][k], prev_activity=k)
               if k!=prev_activity else -1 for k in range(3)])

    return tmp

if __name__ == "__main__":
    n, data = read_input()
    points = f()
    print(points)

Submission status: Wrong Answer

Solution code:
def calc_happiness(h):
    n = len(h)
    if (n == 0):
        return 0

    states = [[None, None, None] for i in range(n)]
    states[0] = h[0]
    for i in range(1, n):
        states[i][0] = h[i][0] + max(states[i-1][1], states[i-1][2])
        states[i][1] = h[i][1] + max(states[i-1][0], states[i-1][2])
        states[i][2] = h[i][2] + max(states[i-1][0], states[i-1][1])
    print(states)
    return max(states[n-1][0], states[n-1][1], states[n-1][2])

if __name__ == "__main__":
    n = int(input())
    h = [[]] * n
    for day in range(n):
        h[day] = list(map(int, input().split(" ")))
    res = calc_happiness(h)
    print(res)

Submission status: Wrong Answer

Solution code:
def calc_happiness(h):
    n = len(h)
    if (n == 0):
        return 0

    states = [[None, None, None]] * len(h)
    states[0] = h[0]
    for i in range(1, n):
        states[i][0] = h[i][0] + max(h[i-1][1], h[i-1][2])
        states[i][1] = h[i][1] + max(h[i-1][0], h[i-1][2])
        states[i][2] = h[i][2] + max(h[i-1][0], h[i-1][1])

    return max(states[n-1][0], states[n-1][1], states[n-1][2])

if __name__ == "__main__":
    n = int(input())
    h = [[]] * n
    for day in range(n):
        h[day] = list(map(int, input().split(" ")))
    res = calc_happiness(h)
    print(res)

Submission status: Wrong Answer

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

Dp = [[] for _ in range(n)]


for i in range(3):
    Dp[0].append(S[0][i])

for i in range(1, n):
    #当日の選択
    for j in range(3):
        #当日選んでいない2つの選択肢に基づくDp
        New_Dp = []
        #1日前の選択
        for k in range(3):
            if j==k:
                continue
            else:
                new_dp = Dp[i-1][j] + S[i][k]
                New_Dp.append(new_dp)
        dp = max(New_Dp)
        Dp[i].append(dp)

ans = max(Dp[-1])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
key = 400
for i in range(N):
    ABC = list(map(int,input().split()))
    x = 0
    for j,value in enumerate(ABC):
        if (key != j) and (value > x):
            x = value
            point = j
    key = point
    ans += x
print(ans)