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())
abc = []
sum = [0]*n
history = []
ava = [[1,2],[0,2],[0,1]]
min = []
for i in range(n):
    abc.append(list(map(int,input().split())))
sum[0] = max(abc[0])
history = abc[0].index(sum[0])
for i in range(1,n):
    #sum[i] = max(sum[i-1]+max(abc[i][ava[history][0]],abc[i][ava[history][1]]),sum[i-1]-abc[i-1][history]+max(abc[i-1][ava[history][0]],abc[-1][ava[history][1]]) + abc[i][history])
    a = sum[i-1]+max(abc[i][ava[history][0]],abc[i][ava[history][1]])
    b = sum[i-1]-abc[i-1][history]+max(abc[i-1][ava[history][0]],abc[i-1][ava[history][1]]) + abc[i][history]
    
    if a >= b:
        sum[i] = a
        history = abc[i].index(max(abc[i][ava[history][0]],abc[i][ava[history][1]]))
    else:
        sum[i] = b
    #print(a,b,history)
print(sum[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = []
sum = [0]*n
history = []
ava = [[1,2],[0,2],[0,1]]
min = []
for i in range(n):
    abc.append(list(map(int,input().split())))
sum[0] = max(abc[0])
history = abc[0].index(sum[0])
for i in range(1,n):
    #sum[i] = max(sum[i-1]+max(abc[i][ava[history][0]],abc[i][ava[history][1]]),sum[i-1]-abc[i-1][history]+max(abc[i-1][ava[history][0]],abc[-1][ava[history][1]]) + abc[i][history])
    a = sum[i-1]+max(abc[i][ava[history][0]],abc[i][ava[history][1]])
    b = sum[i-1]-abc[i-1][history]+max(abc[i-1][ava[history][0]],abc[-1][ava[history][1]]) + abc[i][history]
    
    if a >= b:
        sum[i] = a
        history = abc[i].index(max(abc[i][ava[history][0]],abc[i][ava[history][1]]))
    else:
        sum[i] = b
    #print(a,b,history)
print(sum[i])

Submission status: Wrong Answer

Solution code:
n = int(input())

arrays = []

for _ in range(n):
  day = input()
  day = day.split()
  for i in range(len(day)):
    day[i]=int(day[i])
  arrays.append(day)

result = []
for i in range(len(arrays)):
    if i == 0:
        result.append([max(arrays[i]), arrays[i].index(max(arrays[i]))])
    elif i!=0:
        hasil = result[i-1][1]
        if (arrays[i].index(max(arrays[i])))!= hasil:
            result.append([max(arrays[i]), arrays[i].index(max(arrays[i]))])
        else:
            arrays[i].remove(max(arrays[i]))
            result.append([max(arrays[i]), arrays[i].index(max(arrays[i]))])
jumlah = 0
for i in result:
    jumlah+=i[0]
print(jumlah)

Submission status: Wrong Answer

Solution code:
arrays = [[6, 7, 8],[8, 8, 3],[2, 5, 2],[7, 8, 6],[4, 6, 8],[2, 3, 4],[7, 5, 1]]
result = []
for i in range(len(arrays)):
    maks = max(arrays[i])
    posisiMaks = arrays[i].index(maks)
    if i == 0:
        result.append([maks, posisiMaks])
    elif i!=0:
        hasil = result[i-1][1]
        if posisiMaks != hasil:
            result.append([maks, posisiMaks])
        else:
            arrays[i].remove(maks)
            result.append([max(arrays[i]), arrays[i].index(max(arrays[i]))])
jumlah = 0
for i in result:
    jumlah+=i[0]
print(jumlah)

Submission status: Wrong Answer

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

DP = [[-float("inf"), 0] for i in range(N)]
DP[0][0] = max(act[0])
DP[0][1] = act[0].index(max(act[0]))

for i in range(1,N):
    for j in range(3):
        if DP[i-1][1] == j:
            pass
        else:
            if DP[i][0] < DP[i-1][0] + act[i][j]:
                DP[i][0] = DP[i-1][0] + act[i][j]
                DP[i][1] = j
            else:
                pass

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

Submission status: Wrong Answer

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

DP = [[-float("inf"), 0] for i in range(N)]
DP[0][0] = max(act[0])
DP[0][1] = act[0].index(max(act[0]))

for i in range(1,N):
    for j in range(3):
        if DP[i-1][1] == j:
            pass
        else:
            DP[i][0] = max(DP[i][0], DP[i-1][0] + act[i][j])

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

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] + happy[i-1][k])

res = 0
for i in range(3):
    res = max(res, dp[N][i])

print(res)

#print(happy)

Submission status: Wrong Answer

Solution code:
n=int(input())
abc=[[-1,-1,-1]]
memo=[-1 for i in range(n+1)]
for i in range(n):
  a,b,c=map(int,input().split())
  abc.append([a,b,c])
dp=[0 for i in range(n+1)]
for i in range(1,n+1):
  for j in range(3):
    if memo[i-1]==j:
      continue
    elif dp[i]<dp[i-1]+abc[i][j]:
      memo[i]=j
      dp[i]=dp[i-1]+abc[i][j]
print(dp[-1])

Submission status: Wrong Answer

Solution code:
def max3(lst, n):
  a, b, c = lst[0], lst[1], lst[2]
  if n < 0:
    if a >= b and a >= c:
      return a, 0
    elif b >= a and b >= c:
      return b, 1
    else:
      return c, 2
  elif n == 0:
    if b >= c:
      return b, 1
    else:
      return c, 2
  elif n == 1:
    if a >= c:
      return a, 0
    else:
      return c, 2
  else:
    if a >= b:
      return a, 0
    else:
      return b, 1

n = int(input())
las=-1
first = 0

for i in range(n):
  lst = list(map(int,input().split()))
  res, las = max3(lst, las)
  first += res

print(first)

Submission status: Wrong Answer

Solution code:
def main():

    n = int(input())
    anterior = 4
    suma = 0
    for i in range(n):
        actividad = list(map(int, input().split()))
        mayor = max(actividad)
        indice = actividad.index(mayor)
        if indice != anterior:
            suma = suma + mayor
            anterior = indice
        else:
            actividad[indice] = -1

            nuevo = max(actividad)
            indice = actividad.index(nuevo)
            suma = suma + nuevo
            anterior = indice

    print(suma)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():

    n = int(input())
    anterior = 4
    suma = 0
    for i in range(n):
        actividad = list(map(int, input().split()))
        mayor = max(actividad)
        indice = actividad.index(mayor)
        if indice != anterior:
            suma = suma + mayor
            anterior = indice
        else:
            actividad.pop(indice)
            nuevo = max(actividad)
            indice = actividad.index(nuevo)
            suma = suma + nuevo
            anterior = indice

    print(suma)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
 
lis = []
 
for i in range(n):
  lis.append(list(map(int,input().split())))
 
las=-1
first = 0
 
for val in range(n):
  if las >= 0:
    lis[val][las] = 0
  a = lis[val].index(max(lis[val]))
  if a >= 0:
    las = a
    first += (lis[val][a])
 
print(first)

Submission status: Wrong Answer

Solution code:
n = int(input())
 
lis = []
 
for i in range(n):
  lis.append(list(map(int,input().split())))
 
lis.append([0,0,0])
 
first = 0
 
for val in range(len(lis)-1):
 
  a = lis[val].index(max(lis[val]))
  lis[val+1][a]=0
 
  first += (lis[val][a])
 
print(first)

Submission status: Wrong Answer

Solution code:
n = int(input())

lis = []

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

lis.append([0,0,0])

first = 0

for val in range(len(lis)-1):

  a = lis[val].index(max(lis[val]))

  lis[val+1][a]=0

  first += max(lis[val])

  
print(first)

Submission status: Wrong Answer

Solution code:
days = int(input())
dp = [[0, 0]]*days
sum = 0
dp[0][0], dp[0][1] = -1, -1
for i in range(days):
    l = list(map(int, input().split()))
    x = max(l)
    y = l.index(x)
    if dp[i-1][0] == y:
        l[y] = 0
        dp[i][1] = max(l)
        dp[i][0] = l.index(dp[i][1])
    else:
        dp[i][1] = max(l)
        if l.count(dp[i][1]) > 1:
            dp[i][0] = -1
        else:
            dp[i][0] = l.index(dp[i][1])
    sum += dp[i][1]


print(sum)

Submission status: Wrong Answer

Solution code:
days = int(input())
dp = [[0, 0]]*days
sum = 0
dp[0][0], dp[0][1] = -1, -1
for i in range(days):
    l = list(map(int, input().split()))
    x = max(l)
    y = l.index(x)
    if dp[i-1][0] == y:
        l[y] = 0
        dp[i][1] = max(l)
        dp[i][0] = l.index(dp[i][1])
    else:
        dp[i][1] = max(l)
        dp[i][0] = l.index(dp[i][1])
    sum += dp[i][1]


print(sum)

Submission status: Wrong Answer

Solution code:
def main():
    n, factors = getInputs()

    points = [0] * n
    previous = [-1] * n

    for i in range(n):
        if previous[i - 1] == factors[i][0][0]:
            points[i] =  points[i - 1] + factors[i][1][1]
            previous[i] = factors[i][1][0]
        else:
            points[i] = points[i - 1] + factors[i][0][1]
            previous[i] = factors[i][0][0]

    print(points[-1])

def getInputs():
    n = int(input())

    factors = []
    for i in range(n):
        newFactors = input().split()

        for j in range(3):
            newFactors[j] = (j, int(newFactors[j]))

        newFactors.sort(key=(lambda x: x[1]), reverse=True)
        factors.append(newFactors)

    return n, factors

main()

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] = a
dp[0][1] = b
dp[0][2] = c
for i in range(n-1):
    a, b, c = map(int, input().split())
    dp[i+1][0] = max(dp[i][1]+b, dp[i][2]+c)
    dp[i+1][1] = max(dp[i][0]+a, dp[i][2]+c)
    dp[i+1][2] = max(dp[i][1]+b, dp[i][0]+a)


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

Submission status: Wrong Answer

Solution code:
#dp[x][i]=x日目に、場所iへ、行くときの幸福度の総和の最大値 連日iに行くことはできない縛りがある
#直前＝昨日にいった場所をjとすると、j!=iで表せる 
n=int(input())

dp=[[0 for i in range(3)]for j in range(n)]
happy=[]
for i in range(n):
    a,b,c=map(int,input().split())
    happy.append((a,b,c))
for i in range(n):
    for t_place in range(3):
        for y_place in range(3):
            if t_place==y_place:
                continue
            dp[i][t_place]=max(dp[i][t_place],dp[i-1][y_place]+happy[i][t_place])#昨日来た場所と今日行く場所の幸福度の和
print(max(dp[n-1]))

Submission status: Wrong Answer

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

dp = [[0] * 2 for i in range(N)]
for i in range(N):
    day = array[i]
    for j in range(len(day)):
        if i == 0:
            dp[i][0] = j if dp[i][1] < day[j] else dp[i][0]
            dp[i][1] = day[j] if dp[i][1] < day[j] else dp[i][1]
        else:
            if j != dp[i - 1][0] and dp[i][1] < day[j]:
                dp[i][0] = j
                dp[i][1] = day[j]
sum = 0
for i in range(N):
    sum += dp[i][1]

print(sum)

Submission status: Wrong Answer

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

for i in range(n-1):
    for j in range(3):
        for k in range(3):
            if j == k: #同じことを2日連続はできない
                continue
            dp[i+1][k] = max(dp[i+1][k], li[i+1][j] + dp[i][k])
#print(dp)
print(max(dp[n-1]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    dp = [[0]*3 for i in range(N+1)]
    #dp[i][j] iまでで、j=0はaを選ぶ,j=1はbを選ぶ,j=2はcを選ぶ
    for i in range(1,N+1):
        a, b, c=map(int,input().split())
        dp[i][0] = max(dp[i-1][1]+a, dp[i-1][2]+a, dp[i][0])
        dp[i][1] = max(dp[i-1][2]+b, dp[i-1][0]+b, dp[i][0])
        dp[i][2] = max(dp[i-1][0]+c, dp[i-1][1]+c, dp[i][0])

    print(max(dp[N]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

N = int(input())
V = np.array([[int(i) for i in input().split()] for j in range(N)])

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A,B,C = [],[],[]
for i in range(n):
    a,b,c = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)
dp = [[0]*3 for i in range(n)]
dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

main()

Submission status: Wrong Answer

Solution code:
def main():
    n, *abc = map(int, open(0).read().split())
    dp = [0] * ((n + 1) * 3)
    j = 0
    for i in range(0, n * 3, 3):
        a = j % 3
        b = (j + 1) % 3
        c = (j + 2) % 3
        j += 1
        av = dp[i + b] + abc[i + a]
        bv = dp[i + c] + abc[i + b]
        cv = dp[i + a] + abc[i + c]
        dp[i + 0 + 3] = max(av, bv)
        dp[i + 1 + 3] = max(bv, cv)
        dp[i + 2 + 3] = max(cv, av)
    #print(dp)
    print(max(dp[-1], dp[-2], dp[-3]))

main()

Submission status: Wrong Answer

Solution code:
def resolve():
	# 夏休みの日数
	N = int(input())
	# 日ごとの行動A,B,Cによって得られる幸福度
	ABC = [
		map(int, input().split())
		for _ in range(N)
	]
	# 今日行動A,B,Cをする事で得られる、幸福度の累計
	Va, Vb, Vc = ABC.pop()
	for _ in range(N-1):
		a, b, c = ABC.pop()
		Va, Vb, Vc = max(Vb, Vc) + a, max(Va, Vc) + b, max(Va, Vb) + c
	print(max(Va, Vb, Vc))

Submission status: Wrong Answer

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


dp = [[0 for i in range(3)] for j in range(n)]
dp[0][0] = total[0][0]
dp[0][1] = total[0][1]
dp[0][2] = total[0][2]

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

print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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][2] = max(dp[i-1][0], dp[i-1][1]) + c

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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][2] = 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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N = INT()
abc = [LIST() for _ in range(N)]
a, b, c = [0]*N, [0]*N, [0]*N

ans = 0
idx = -1
for i in range(N):
	idx = abc[i].index(max(abc[i][j] for j in range(3) if j != idx))
	ans += abc[i][idx]

print(ans)

Submission status: Wrong Answer

Solution code:
a=list()
n=int(input())
for i in range(n):
  lis=list(map(int,input().split()))
  a.append(lis)
ans=0
ind=-1
for i in a:
  if ind == i.index(max(i)):
    del i[i.index(max(i))]
  ans = ans+max(i)
  ind = i.index(max(i))
print(ans)

Submission status: Wrong Answer

Solution code:
class Solution:
	def __init__(self):
		pass
	def solve(self,arr):
		dp=[0]*len(arr)
		dp[0]=arr[0].index(max(arr[0]))
		for i in range(1,len(arr)):
			arr[i][dp[i-1]]=0
			dp[i]=arr[i].index(max(arr[i]))
		res=0
		for i in range(len(arr)):
			res+=arr[i][dp[i]]
		return(res)
obj=Solution()
#print(obj.solve([[6,7,8],[8,8,3],[2,5,2],[7,8,6],[4,6,8],[2,3,4],[7,5,1]]))
n=int(input().strip())
activities=[]
for i in range(n):
	a=list(map(int,input().split()))
	activities.append(a)
print(obj.solve(activities))

Submission status: Wrong Answer

Solution code:
N = int(input())
profit = [list(map(int, input().split())) for i in range(N)]
#dp[i][p] をi日目にｐをしたときのi日目までの最大値
#dpを初期化
dp = [[0 for j in range(3)] for i in range(N)]
# for p in range(3):
    # dp[0][p] = profit[0][p]

#dpの更新
for i in range(N):
    for p in range(3):
        dp[i][p] = max(dp[i-1][p-1],dp[i-1][p-2]) + profit[i][p]
print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j == k:
        continue
      else:
        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())

yesterday = "d"
happiness = 0
for i in range(n):
  point = list(map(int,input().strip().split()))
  if yesterday == 0:
    point[0] = 0
  elif yesterday == 1:
    point[1] = 0
  elif yesterday == 2:
    point[2] = 0
  yesterday = point.index(max(point))
  happiness += max(point)
print(happiness)

Submission status: Wrong Answer

Solution code:
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def maxim(i,char):
    if i<0:
        return 0
    if d[i,char]!=-1:
        print('hi')
        print(i,char)
        return d[i,char]
    if char=='C':
        d[i,char]= max(c[i]+maxim(i-1,'B'),c[i]+maxim(i-1,'A'))
        return d[i,char]
    if char=='B':
        d[i,char]= max(b[i] + maxim(i - 1, 'A'), b[i] + maxim(i - 1, 'C'))
        return d[i,char]
    if char=='A':
        d[i,char]= max(a[i] + maxim(i - 1, 'B'), a[i] + maxim(i - 1, 'C'))
        return d[i,char]
n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    d=dict()
    for i in range(n):
        d[i,'A']=-1
        d[i,'B']=-1
        d[i,'C']=-1
    a.append(x)
    b.append(y)
    c.append(z)
print(max(maxim(n-1,'C'),maxim(n-1,'B'),maxim(n-1,'A')))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys,io
from functools import lru_cache
import numpy
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
a,b,c=[0]*n,[0]*n,[0]*n
for i,line in enumerate(readlines()):
    a[i],b[i],c[i]=mp(line)
dp=[[0,0,0] for i in range(n+1)]
print(dp)
for k in range(1,n+1):
    one=dp[k-1][1]
    two=dp[k-1][2]
    zero=dp[k-1][0]
    dp[k][0]= one if one >= two else two
    dp[k][0]+=a[k-1]
    dp[k][1]= zero if zero >= two else two
    dp[k][1]+=b[k-1]
    dp[k][2]= one if one >= zero else zero
    dp[k][2]+=c[k-1]
print(dp)
print(max(dp[n][0],dp[n][1],dp[n][2]))

Submission status: Wrong Answer

Solution code:
import sys,io
from functools import lru_cache
import numpy
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
a,b,c=[0]*n,[0]*n,[0]*n
for i,line in enumerate(readlines()):
    a[i],b[i],c[i]=mp(line)
dp=[[0,0,0] for i in range(n+1)]
print(dp)
for k in range(1,n+1):
    one=dp[k-1][1]+a[k-1]
    two=dp[k-1][2]+b[k-1]
    zero=dp[k-1][0]+c[k-1]
    dp[k][0]= one if one >= two else two
    dp[k][1]= zero if zero >= two else two
    dp[k][2]= one if one >= zero else zero
print(max(dp[n][0],dp[n][1],dp[n][2]))

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)]
print(dp)
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][2] + a[i + 1])
	dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
	dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
print(max(dp[N - 1]))

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)
def calc(ans1, prev):
  for i in range(1,n):
    if prev == 0:
      if b[i]>c[i]:
        ans1 += b[i];prev = 1
      else:
        ans1 += c[i];prev = 2
    elif prev == 1:
      if a[i]>c[i]:
        ans1 += a[i];prev = 0
      else:
        ans1 += c[i];prev = 2
    else:
      if a[i]>b[i]:
        ans1 += a[i];prev = 0
      else:
        ans1 += b[i];prev = 1
  return ans1
print(max(calc(a[0],0),calc(b[0],1),calc(c[0],2)))

Submission status: Wrong Answer

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

import sys

def main():
    n = int(input())
    datas=list([[int(i) for i in input().split()] for _ in range(n)])
    stack=[]
    happy=0
    for data in datas:
        if len(stack)==0:
            stack.append(data.index(max(data)))
            happy+=(max(data))
        else:
            stack_idx=stack.pop()
            if stack_idx==data.index(max(data)):
                #最大値を-1に置き換える
                data[stack_idx]=-1
                stack.append(data.index(max(data)))
                happy+=(max(data))
            else:
                stack.append(data.index(max(data)))
                happy+=(max(data))
    print(happy)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import sys

def main():
    n = int(input())
    datas=list([[int(i) for i in input().split()] for _ in range(n)])
    ashiato_stack=[]
    happy=0
    for data in datas:
        if len(ashiato_stack)==0:
            ashiato_stack.append(data.index(max(data)))
            happy+=(max(data))
        else:
            stack_idx=ashiato_stack.pop()
            if stack_idx==data.index(max(data)):
                data[stack_idx]=0
                ashiato_stack.append(data.index(max(data)))
                happy+=(max(data))
            else:
                ashiato_stack.append(data.index(max(data)))
                happy+=(max(data))
    print(happy)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
    n = int(input())
    datas=list([[int(i) for i in input().split()] for _ in range(n)])
    ashiato_stack=[]
    happy=0
    for data in datas:
        if len(ashiato_stack)==0:
            ashiato_stack.append(data.index(max(data)))
            happy+=(max(data))
        else:
            stack_idx=ashiato_stack.pop()
            if stack_idx==data.index(max(data)):
                data[stack_idx]=0
                ashiato_stack.append(data.index(max(data)))
                happy+=(max(data))
            else:
                ashiato_stack.append(data.index(max(data)))
                happy+=(max(data))
    print(happy)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
for i in range(N):
  ans += max(list(map(int,input().split())))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
happy = 0
yesterday = -1
for i in range(n):
    M = 0
    do = list(map(int, input().split()))
    for j in range(3):
        if j != yesterday and M < do[j]:
            M = do[j]
            today = j
        elif j != yesterday and M == do[j]:
            today = -1
    happy += M
    yesterday = today
print(happy)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:



n = int(input())
best = [-999999999]*n
best[0] = 0
last = None
for i in range(n):
    if i != 0:
        best[i] = best[i - 1]
    scores = list(map(int, input().split()))
    if last is None:
        score,ind = -1,0
        for j in range(len(scores)):
            if scores[j] > score:
                score = scores[j]
                ind = j
        best[i] = max(0, score)
        last = ind
    else:
        score, ind = -999999999,0
        for j in range(len(scores)):
            if scores[j] > score and j!=last:
                score = scores[j]
                ind = j
        best[i] = best[i-1]
        best[i] = max(best[i-1], best[i-1]+score)
        last = ind

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

Submission status: Wrong Answer

Solution code:



n = int(input())
best = [-999999999]*n
best[0] = 0
last = None
for i in range(n):
    if i!=0:
        best[i] = best[i - 1]
    scores = list(map(int, input().split()))
    if last is None:
        score,ind = -1,0
        for j in range(len(scores)):
            if scores[j] > score:
                score = scores[j]
                ind = j
        best[i] = score
        last = ind
    else:
        score, ind = -999999999,0
        for j in range(len(scores)):
            if scores[j] > score and j!=last:
                score = scores[j]
                ind = j
        best[i] = best[i-1]
        best[i] += score
        last = ind

print(best[-1])

Submission status: Wrong Answer

Solution code:



n = int(input())
best = [-999999999]*n
last = None
for i in range(n):
    scores = list(map(int, input().split()))
    if last is None:
        score,ind = -1,0
        for j in range(len(scores)):
            if scores[j] > score:
                score = scores[j]
                ind = j
        best[i] = score
        last = ind
    else:
        score, ind = -999999999,0
        for j in range(len(scores)):
            if scores[j] > score and j!=last:
                score = scores[j]
                ind = j
        best[i] = best[i-1]
        best[i] += score
        last = ind

print(best[-1])

Submission status: Wrong Answer

Solution code:



n = int(input())
best = [0]*n
last = None
for i in range(n):
    scores = list(map(int, input().split()))
    if last is None:
        score,ind = -1,0
        for j in range(len(scores)):
            if scores[j] > score:
                score = scores[j]
                ind = j
        best[i] = score
        last = ind
    else:
        score, ind = -1,0
        for j in range(len(scores)):
            if scores[j] > score and j!=last:
                score = scores[j]
                ind = j
        best[i] = best[i-1]
        best[i] += score
        last = ind

print(best[-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
def dprint(*args):
  if debug:
    if len(args)==1:
      print(args[0])
    else:
      print(args)

debug = False
if debug:
  N=3
  ABC=[[10, 40, 70], [20, 50, 80], [30, 60, 90]]
else:
  N = int(input())
  ABC=[]
  for i in range(N):
    ABC.append(list(map(int,input().split())))

dprint(N,ABC)

# i -> 1 to N
# ABC -> 012

H = np.zeros((N,3))
H[0]=ABC[0]

for j in range(1,N):
  H[j][0]=max(H[j][0], H[j-1][1]+ABC[j][0], H[j-1][2]+ABC[j][0])
  H[j][1]=max(H[j][1], H[j-1][0]+ABC[j][1], H[j-1][2]+ABC[j][1])
  H[j][2]=max(H[j][2], H[j-1][0]+ABC[j][2], H[j-1][1]+ABC[j][2])

print(max(H[-1]))