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

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

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


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

Submission status: Wrong Answer

Solution code:


n = int(input())

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] = li[0]

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[]
for i in range(n):
    A.append(list(map(int,input().split())))
prev=-100000
sum=0
tick=-10000000
for i in range(len(A)):
    max=0
    print("**",prev)
    for j in range(len(A[i])):
        if(j!=tick and max<A[i][j]):
            max=A[i][j]
            prev=j
            print(A[i][j],prev)
    sum=sum+max
    tick=prev
print(sum)

Submission status: Wrong Answer

Solution code:

if __name__ == '__main__':

    n = int(input())
    A = [0]
    B = [0]
    C = [0]
    
    for i in range(n):
        a,b,c = map(int,input().split())
        A.append(a)
        B.append(b)
        C.append(c)
        
    INF = -10**9
    dp = [INF] * (n+1)
    dp[0] = 0
    flg = 0
    ans = 0
    for i in range(1,4):
        dp = [INF] * (n+1)
        dp[0] = 0
        if i == 1:
            flg = 0
        elif i == 2:
            flg = 1
        else:
            flg = 2
        for k in range(1,n+1):
            if flg == 0:
                if B[k] >= C[k]:
                    dp[k] = dp[k-1] + B[k]
                    flg = 1
                else:
                    dp[k] = dp[k-1] + C[k]
                    flg = 2
            elif flg == 1:
                if A[k] >= C[k]:
                    dp[k] = dp[k-1] + A[k]
                    flg = 0
                else:
                    dp[k] = dp[k-1] + C[k]
                    flg = 2
                flg = 0
            else:
                if A[k] >= B[k]:
                    dp[k] = dp[k-1] + A[k]
                    flg = 0
                else:
                    dp[k] = dp[k-1] + B[k]
                    flg = 1
        ans = max(ans,dp[n])
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

dp = [0] * n
dp[0] = max([abc[0][k] for k in range(3)])
p_color = abc[0].index(dp[0])

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
abc = []
for i in range(N):
  abc.append([int(i) for i in input().split()])
abc.append([0,0,0])
dp = np.zeros([N+1,3])
print(dp)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
abc = []
for i in range(N):
  abc.append([int(i) for i in input().split()])
dpmax = [max(x) for x in abc]
dpmid = [sorted(x)[1] for x in abc]

for i in range(1,N):
  #print(dpmax[i],dpmid[i-1], dpmax[i-1],dpmid[i] )
  dpmax[i] = max(dpmax[i]+dpmid[i-1], dpmax[i-1]+dpmid[i])
  dpmid[i] = min(dpmax[i]+dpmid[i-1], dpmax[i-1]+dpmid[i])
print(dpmax[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())

aa = 0
bb = 0
cc = 0 

for i in range(n):
    a,b,c = map(int,input().split())
    aa,bb,cc = max(bb + a, cc + a),max(aa + b, cc + b),max(aa + c, bb + c)

    print(aa,bb,cc)
print(max(aa,bb,cc))

Submission status: Wrong Answer

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


dp = [[0, 0, 0]]*n
dp[0] = X[0]


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

print(max(dp[-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    dp = [0] * N
    ans = 0
    for i in range(N):
        a, b, c = map(int, input().split())
        d = {'a': a, 'b': b, 'c': c}
        for k, v in sorted(d.items(), key=lambda x: -x[1]):
            if i == 0:
                ans += v
                dp[i] = k
                break
            elif i != 0 and dp[i-1] != k:
                ans += v
                dp[i] = k
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
a,b,c = [list(i) for i in zip(*l)]
dp = [[0,0] for i in range(n)]
if a[0] >= b[0] and a[0] >= c[0]:
    dp[0] = [a[0],0]
if b[0] >= a[0] and b[0] >= c[0]:
    dp[0] = [b[0],1]
if c[0] >= a[0] and c[0] >= b[0]:
    dp[0] = [c[0],2]
for i in range(1,n):
    if dp[i-1][1] == 0:
        if b[i] >= c[i]:
            dp[i] = [dp[i-1][0]+b[i],1]
        else:
            dp[i] = [dp[i-1][0]+c[i],2]
    if dp[i-1][1] == 1:
        if a[i] >= c[i]:
            dp[i] = [dp[i-1][0]+a[i],0]
        else:
            dp[i] = [dp[i-1][0]+c[i],2]
    if dp[i-1][1] == 2:
        if a[i] >= b[i]:
            dp[i] = [dp[i-1][0]+a[i],0]
        else:
            dp[i] = [dp[i-1][0]+b[i],1]
print(dp[-1][0])

Submission status: Wrong Answer

Solution code:

n = int(input())
summmer = [""]*n
for i in range(n):
    summmer[i] = list(map(int,input().split()))
happy = [0]*(n+1)
yesterday = -1
for i in range(1,n+1):
    for j in range(3):
        if(j != yesterday):
            if(happy[i-1]+summmer[i-1][j] > happy[i]):
                happy[i] = happy[i-1] + summmer[i-1][j]
                today = j
    yesterday = today
    # print(happy,yesterday)
print(happy[-1])

Submission status: Wrong Answer

Solution code:
# 問題C
import numpy as np
import warnings
warnings.filterwarnings('ignore')

N = int(input())
h = np.array([list(map(int, input().split())) for _ in range(N)])
print(h)

h = h.reshape(N, 3)

dp = np.array([[0] * h.shape[1]] * h.shape[0])
dp[0, :] = h[0, :]
for i in range(1, N):
    dp[i, 0] = max(dp[i-1, 1], dp[i-1, 2])+h[i, 0]
    dp[i, 1] = max(dp[i-1, 0], dp[i-1, 2])+h[i, 1]
    dp[i, 2] = max(dp[i-1, 0], dp[i-1, 1])+h[i, 2]

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

Submission status: Wrong Answer

Solution code:

n = int(input())
x = [-1]*n
for i in range(n):
    x[i] = list(map(int, input().split()))

ans = [[0]*3 for i in range(n)]
ans[0] = x[0]

for k in range(1,n):
    for j in range(3):
        ans[k][j] = max(ans[k-1][(j+1)%3], ans[k-1][(j+2)%3]) + x[k][j]
    print(ans[i])

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

Submission status: Wrong Answer

Solution code:

n = int(input())
x = [-1]*n
for i in range(n):
    x[i] = list(map(int, input().split()))

ans = [[0]*3 for i in range(n)]
ans[0] = x[0]

for k in range(1,n):
    for j in range(3):
        ans[k][j] = max(ans[k-1][(j+1)%3], ans[k-1][(j+2)%3]) + x[k][j]
    print(ans[i])

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

"""
def maxFun(n):

    if (n == 0):
        return 0;
        ans[0][0] = max(x[0])
        ans[0][1] = x[0].index(max(x[0]))
    else:
        for i in range(3)
            ans[n-1][i] =
        t = ans[n-2][1]
        tmp = [(t+1)%3,(t+2)%3]
        maxt = max(x[n-1][tmp[0]],x[n-1][tmp[1]])
        ans[n-1][0] = maxFun(n-1) + maxt
        ans[n-1][1] = x[n-1].index(maxt)
    return ans[n-1][0]

print(maxFun(n))

    if (t[n-2] == 0):
        mfun[n-1] = mfun[n-2] + max(x[n-1])
        if (max(x[n-1]) == x[n-1][1]):
            t[n-1] = 1
        else:
            t[n-1] = 2
    elif (t[n] == 1):
        mfun[n] = max(mfun[n-1] + max(x[n-1]))
        if (max(x[n-1]) == x[n-1][0]):
            t[n-1] = 0
        else:
            t[n-1] = 2
    elif
    """

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
N = int(input())
A = []
for _ in range(N):
    a,b,c = map(int,input().split())
    A.append((a,b,c))
    
# 無限大の値
INF = 10**10

# DP テーブル (値と前に選んだ活動を保持)
# a (j = 0), b (j = 1), c (j = 2)に記録
dp = [[0]*3 for _ in range(100010)]

# DP テーブル全体を初期化
for i in range(100010):
    for j in range(3):
        dp[i][j] = -INF# 最大化問題

def rec(v):
    # v 日目の活動
    for w in range(3):
        # DP の値がすでに更新されていたらそのままリターン
        if dp[v][w] > -INF:
            return dp[v]
        # 初期条件
        if v == 0:
            dp[v][w] = 0
            return dp[v]
        # v-1 を再帰
        res = -INF
        for k in range(3):
            # 前日と活動が同じならスルー
            if w == k:
                continue
            res = max(res, rec(v-1)[k] + A[v-1][w])
            # 結果をメモして返す
            dp[v][w] = res
    return dp[v]
rec(N)
ans = max(dp[N])
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math
n=int(input())
K=3
dp=[[0]*K for _ in range(n)]

for i in range(n):
    a=list(map(int,input().split()))
    for j in range(K):
        for k in range(K):
            if j==k:
                continue
            dp[i][j]=max(dp[i][j],dp[i-1][k]+a[k])
print(max(dp[n-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
l = []
for i in range(n):
    l.append(list(map(int , input().split())))
#arr = np.array(l)
maxc = max(l[0])
#print(maxc)
ind = l[0].index(maxc)
for r in range(1,n):
    max1 = 0
    for i in range(3):
        if(ind != i):
            max1 = max(max1,l[r][i])
    ind = l[r].index(max1)
    #print(max1)
    maxc += max1
print(maxc)

Submission status: Wrong Answer

Solution code:
import math


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


def chmin(a, b):
    if a <= b:
        return a
    return b


def main():
    nn = int(input())
    arr = [list(map(int, input().split())) for l in range(nn)]
    dp = [[0] * 3 for i in range(nn)]

    for i in range(0,nn):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i][j] = chmax(dp[i][j],dp[i-1][k]+arr[i][k])

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


main()

Submission status: Wrong Answer

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

max_ind=arr[0].index(max(arr[0]))
max_sum=max(arr[0])

for i in range(1,len(arr)):
  temp=arr[i]
  temp.pop(max_ind)
  max_sum+=max(temp)
  max_ind=temp.index(max(temp))

print(max_sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [["s",0] for i in range(n)]
a,b,c = map(int,input().split())
if a>b and a>c:
    dp[0][0] = "a"
    dp[0][1] = a
elif b>a and b>c:
    dp[0][0] = "b"
    dp[0][1] = b
else:
    dp[0][0] = "c"
    dp[0][1] = c

for i in range(1,n):
    a,b,c = map(int,input().split())
    if dp[i-1][0] == "a":
        if b>c:
            dp[i][0] = "b"
            dp[i][1] = dp[i-1][1]+b
        else:
            dp[i][0] = "c"
            dp[i][1] = dp[i-1][1]+c
    elif dp[i-1][0] == "b":
        if a>c:
            dp[i][0] = "a"
            dp[i][1] = dp[i-1][1]+a
        else:
            dp[i][0] = "c"
            dp[i][1] = dp[i-1][1]+c
    else:
        if b>a:
            dp[i][0] = "b"
            dp[i][1] = dp[i-1][1]+b
        else:
            dp[i][0] = "a"
            dp[i][1] = dp[i-1][1]+a

print(dp[-1][1])

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    abc = in_nl2(N)

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

    dp[0][0] = abc[0][0]
    dp[1][0] = abc[0][1]
    dp[2][0] = abc[0][2]

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
temp=100
ans=0
for i in range(n):
  s=list(map(int,input().split()))
  if temp==0:
    ans+=max(s[1], s[2])
    temp=s.index(max(s[1], s[2]))
  elif temp==1:
    ans+=max(s[0], s[2])
    temp=s.index(max(s[0], s[2]))
  elif temp==2:
    ans+=max(s[1], s[0])
    temp=s.index(max(s[1], s[0]))
  else:
    ans+=max(s)
    temp=s.index(max(s))
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

print(max(dp[-1]))

Submission status: Wrong Answer

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

dp = [[0,0]]*(N+1)
m = max(a[0])
j = a[0].index(m)
dp[0][0] = m
dp[0][1] = j
for i in range(1,N):
	prev = dp[i-1][1]
	m = 0
	for j in range(3):
		if j!=prev:
			m = max(a[i][j],m)
	j = a[i].index(m)
	dp[i][0] = dp[i-1][0] + m
	dp[i][1] = j
print(dp[N-1][0])

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(n):
    x= list(map(int, input().split()))
    l.append(x)
#print(l)
maxval = []
profit = []
for i in l:
    m = max(i)
    #print(m)
    c = 0
    val = []
    for xx in i:
        if xx==m:
            val.append(c)
        c+=1
    maxval.append(val)
    sec = sorted(i)[1]
    profit.append(m-sec)
#print(maxval, profit)
c = 0
for i in maxval:
    if len(i)>1:
        try:
            if (maxval[c+1])[0]==i[0]:
                maxval[c]=i[1]
            else:
                maxval[c]=i[0]
        except:
            maxval[c] = i[0]
    else:
        maxval[c] = i[0]
    c+=1
#print(maxval)
c = 0
for i in maxval:
    if c==n-1:
        continue
    if c==0 and i==maxval[c+1]:
        if profit[c]<profit[c+1]:
            maxval[c] = l[c].index(sorted(l[c])[1])
        else:
            #print(True)
            maxval[c+1] = l[c+1].index(sorted(l[c+1])[1])
        c+=1
        continue
    if c==0:
        c+=1
        continue
    if i==maxval[c+1] and i==maxval[c-1]:
        if profit[c]<=profit[c-1]+profit[c+1]:
            maxval[c] = l[c].index(sorted(l[c])[1])
        else:
            maxval[c+1] = l[c+1].index(sorted(l[c+1])[1])
            maxval[c-1] = l[c-1].index(sorted(l[c-1])[1])
    elif i==maxval[c+1]:
        if profit[c]<=profit[c+1]:
            maxval[c] = l[c].index(sorted(l[c])[1])
        else:
            maxval[c+1] = l[c+1].index(sorted(l[c+1])[1])
    elif i==maxval[c-1]:
        if profit[c]<=profit[c-1]:
            maxval[c] = l[c].index(sorted(l[c])[1])
        else:
            maxval[c-1] = l[c-1].index(sorted(l[c-1])[1])
    c+=1
ans = 0
c = 0
for y in maxval:
    ans+=l[c][y]
    c+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
i = -1
H = 0
for _ in range (N):
  L = list(map(int, input().split()))
  k = max(L)
  if L.index(k) == i:
    L[L.index(k)] = 0
    k = max(L)
  H += k
  i = L.index(k)
print(H)

Submission status: Wrong Answer

Solution code:
#import
#import math
#import numpy as np
#= input()
#= map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]
N = int(input())
a = []

# dp[i][0]:Aを選んだ  dp[i][1]:Bを選んだ  dp[i][2]:Cを選んだ 

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

for _ in range(N):
    aa = list(map(int, input().split()))
    a.append(aa)

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


print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
#import
#import math
#import numpy as np
#= input()
#= map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]
N = int(input())
a = []

# dp[i][0]:Aを選んだ  dp[i][1]:Bを選んだ  dp[i][2]:Cを選んだ 

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

for _ in range(N):
    aa = list(map(int, input().split()))
    a.append(aa)

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


print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
#import
#import math
#import numpy as np
N = int(input())
#= input()
#= map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]

a = []

# dp[i][0]:Aを選んだ  dp[i][1]:Bを選んだ  dp[i][2]:Cを選んだ 

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

for _ in range(N):
    aa = list(map(int, input().split()))
    a.append(aa)

for i in range(1, N+1):
    for j in range(3):
        t = 0
        for k in range(3):
            if j != k:
                tt = dp[i - 1][j] + a[i - 1][k]
                if t < tt:
                    dp[i][k] = dp[i-1][j] + a[i - 1][k]


print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
x=int(input())
days=[]
for i in range(x):
    days.append(list(map(int,input().split())))
print(days)
dp=[0]*3
dp=days[0]
for cur in range(1,x):
    m=[0]*3
    for i in range(3):
        for j in range(3):
            if i!=j:
                m[i]=max(m[i],days[cur][i]+dp[j])
    dp=m
print(max(dp))

Submission status: Wrong Answer

Solution code:
x=int(input())
count=0
hap=list(map(int,input().split()))
count=max(hap)
k=hap.index(count)
for _ in range(1,x):
    hap=list(map(int,input().split()))
    m=-1
    for j in range(len(hap)):
        if j!=k:
            if hap[j]>m:
                m=hap[j]
                ano=j
    count+=m
    k=ano
print(count)

Submission status: Wrong Answer

Solution code:
x=int(input())
count=0
hap=list(map(int,input().split()))
count=max(hap)
k=hap.index(count)
for i in range(1,x):
    hap=list(map(int,input().split()))
    m=-1
    for j in range(len(hap)):
        if j!=k:
            if hap[j]>=m:
                m=hap[j]
                ano=j
    count+=m
    k=ano
print(count)

Submission status: Wrong Answer

Solution code:
x=int(input())
count=0
k=-1
hap=list(map(int,input().split()))
count=max(hap)
k=hap.index(count)
for i in range(1,x):
    hap=list(map(int,input().split()))
    m=-1
    for j in range(len(hap)):
        if j!=k:
            if hap[j]>m:
                m=hap[j]
                ano=j
    count+=m
    k=ano
print(count)

Submission status: Wrong Answer

Solution code:
x=int(input())
count=0
k=-1
hap=list(map(int,input().split()))
count=max(hap)
k=hap.index(count)
for i in range(1,x):
    hap=list(map(int,input().split()))
    m=-1
    for i in range(len(hap)):
        if i!=k:
            m=max(hap[i],m)
            ano=i
    count+=m
    k=ano
print(count)

Submission status: Wrong Answer

Solution code:
def solve(N, a, b, c):
    dp = [-1 for i in range(N+1)]
    DP = [0 for i in range(N+1)]
    DP[1] = max(a[1], b[1], c[1])
    for i in range(1, N):
        if DP[i]-DP[i-1] == a[i]:
            dp[i] = 0
        elif DP[i]-DP[i-1] == b[i]:
            dp[i] = 1
        elif DP[i]-DP[i-1] == c[i]:
            dp[i] = 2
        if dp[i] == 0:
            DP[i+1] = DP[i] + max(b[i+1], c[i+1])
        elif dp[i] == 1:
            DP[i+1] = DP[i] + max(c[i+1], a[i+1])
        elif dp[i] == 2:
            DP[i+1] = DP[i] + max(a[i+1], b[i+1])
    return DP[N]
N = int(input())
a = [0]
b = [0]
c = [0]
for i in range(N):
    a_i, b_i, c_i = map(int, input().split())
    a.append(a_i)
    b.append(b_i)
    c.append(c_i)
print(solve(N, a, b, c))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# N回ループで、ABCのうち最大を選択、記録して翌日はABCのうち前日と異なる最大値
N = int(input())
H = [0]*N
abc = list(map(int, input().split()))
H[0] = max(abc)
k = abc.index(H[0])
for i in range(1, N):
    abc = list(map(int, input().split()))
    # kは前日に選択した0,1,2のいずれかとして
    H[i] = max(abc[k-1],abc[(k+1)%3])
    k = abc.index(H[i])
print(sum(H))

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = [list(map(int, input().split())) for i in range(n)]
dp = [-1] * n
m = max(abc[0])
dp[0] = m
x = abc[0].index(m)

for i in range(1,n):
    t = -1
    for j in range(3):
        if x == j:
            continue
        if dp[i] < dp[i-1]+abc[i][j]:
            t = j
            dp[i] = dp[i-1]+abc[i][j]
    x = t
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = [list(map(int, input().split())) for i in range(n)]
dp = [-1] * n
m = max(abc[0])
dp[0] = m
x = abc[0].index(m)

for i in range(1,n):
    m = -1
    t = -1
    for j in range(3):
        if x == j:
            continue
        if m < abc[i][j]:
            m = abc[i][j]
            t = j
    x = t
    dp[i] = m + dp[i-1]
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = [list(map(int, input().split())) for i in range(n)]
dp = [-1] * n
m = max(abc[0])
dp[0] = m
x = abc[0].index(m)

for i in range(1,n):
    m = -1
    t = -1
    for j in range(3):
        if x == j:
            continue
        print(j,x)
        if m < abc[i][j]:
            m = abc[i][j]
            t = j
    x = t
    dp[i] = m + dp[i-1]
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
dp=[[0 for i in range(3)] for i in range(n)]
ans = 0
I=[0]*n
for i in range(n):
    dp[i]=list(map(int,input().split()))
    S=dp[i].copy()
    S.sort(reverse = True)
    if i == 0 or dp[i].index(S[0]) != I[i-1]:
        I[i]=dp[i].index(S[0])
        ans += S[0]
    else:
        I[i]=dp[i].index(S[1])
        ans += S[1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
dp=[[0 for i in range(3)] for i in range(n)]
ans = 0
I=[-1]*n
for i in range(n):
    dp[i]=list(map(int,input().split()))
    S=dp[i].copy()
    S.sort(reverse = True)
    if dp[i].index(S[0]) != I[i-1]:
        I[i]=dp[i].index(S[0])
        ans += S[0]
    else:
        I[i]=dp[i].index(S[1])
        ans += S[1]
print(ans)

Submission status: Wrong Answer

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


dp = [-1]*(d+1)
dp[0] = 0

h=-1
for i in range(1,d+1):
    maxi = 0
    x=0
    for j in range(0,3):
        if j==h:
            continue
        else:
            if dp[i-1] + m[i-1][j]>maxi:
                maxi = dp[i-1] + m[i-1][j]
                x=j
    dp[i] = maxi
    h=x
    # print(h)

print(dp[-1])

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = np.zeros((N,3))
for i in range(N):
    a[i][0],a[i][1],a[i][2] = map(int,input().split())

memo = np.zeros((N,3))

memo[0][0], memo[0][1], memo[0][2] = a[0][0],a[0][1],a[0][2]
day = 1

while (day < N):
    memo[day] = [max(memo[day-1][(x+1)%3],memo[day-1][(x+2)%3]) + a[day][x] \
                   for x in [0,1,2]]
    day += 1

print(max(memo[day - 1]))

Submission status: Wrong Answer

Solution code:
n = int(input())

all_days = []
for _ in range(n):
  day = input()
  day = day.split()
  for k in range(len(day)):
    day[k] = int(day[k])
  all_days.append(day)
  
arrays = all_days
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:
N = int(input())
dp = [0] * (N + 1)

pre = ""
for i in range(1, N + 1):
    a, b, c = map(int, input().split())
    if pre != "a" and dp[i] < dp[i - 1] + a:
        dp[i] = dp[i - 1] + a
        p = "a"
    if pre != "b" and dp[i] < dp[i - 1] + b:
        dp[i] = dp[i - 1] + b
        p = "b"
    if pre != "c" and dp[i] < dp[i - 1] + c:
        dp[i] = dp[i - 1] + c
        p = "c"
    pre = p

print(dp[N])

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-2]+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]]))
    elif a==b:
        sum[i] = a
        if(abc[i][ava[history][0]]>abc[i][ava[history][1]]):
            history = ava[history][1]
        else:
            history = ava[history][0]
        #history = abc[i].index(min(abc[i][ava[history][0]],abc[i][ava[history][1]]))
    else:
        sum[i] = b
        #print("canged=>",abc[i-1].index(max(abc[i-1][ava[history][0]],abc[i-1][ava[history][1]])))
    #print(history,sum[i])
print(sum[i])