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())
ans = 0
key = -5
for i in range(N):
    ABC = list(map(int,input().split()))
    a = max(ABC[:key],ABC[key+1:])
    b = max(a)
    key = ABC.index(b)
    ans += b
print(ans)

Submission status: Wrong Answer

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

dp = [0] * (N+1)
pre = None
for i in range(N):
    m = 0
    cur = None
    for j in range(3):
        if pre == j:
            continue
        elif m < abc[i][j]:
            m = abc[i][j]
            cur = j
    pre = cur
    dp[i+1] = max(dp[i+1], dp[i] + m)
print(dp[-1])

Submission status: Wrong Answer

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

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

print(max(a[-1],b[-1],c[-1]))

Submission status: Wrong Answer

Solution code:
import math
import numpy as np


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    act = []
    for i in range(N):
        act.append(inputIntList())
    act.append([0, 0, 0])
    dp = [[0 for _ in range(3)] for _ in range(N + 1)]
    dp[0] = act[0]
    for i in range(N):
        for j in range(3):
            dp[i + 1][j] = dp[i][j] + max(act[i + 1][j - 1], act[i + 1][j - 2])
            # print(dp)

    return max(dp[-1])


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

Submission status: Wrong Answer

Solution code:
import math
import numpy as np


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    act = []
    for i in range(N):
        act.append(inputIntList())
    act.append([0, 0, 0])
    dp = [0 for _ in range(N + 1)]
    for i in range(N):
        dp[i + 1] = dp[i] + max(act[i])
        act[i + 1][np.argmax(act[i])] = 0
        # print(np.argmax(act[i]))

    return dp[-1]


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

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 for i in range(3)]for i in range(n)]
for i in range(n):
    for j in range(3):
        if j == 0:
            s = a[i]
        if j == 1:
            s = b[i]
        if j == 2:
            s = c[i]
        for k in range(3):
            if i !=0:
                if j != k:
                    dp[i][j] = max(dp[i-1][k],dp[i][j])
        dp[i][j] += s
print(dp)
print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))

Submission status: Wrong Answer

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

for i in range(1, n):
    for j in range(3):
        if dp[i - 1][j][1] == 0:
            for k in [1, 2]:
                t = (b[i] if k == 1 else c[i])
                if dp[i - 1][j][0] + t > dp[i][j][0]:
                    dp[i][j] = [dp[i - 1][j][0] + t, k]
        elif dp[i - 1][j][1] == 1:
            for k in [2, 0]:
                t = (c[i] if k == 2 else a[i])
                if dp[i - 1][j][0] + t > dp[i][j][0]:
                    dp[i][j] = [dp[i - 1][j][0] + t, k]
        else:
            for k in [0, 1]:
                t = (b[i] if k == 1 else a[i])
                if dp[i - 1][j][0] + t > dp[i][j][0]:
                    dp[i][j] = [dp[i - 1][j][0] + t, k]


print(max([i[0] for i in dp[-1]]))

Submission status: Wrong Answer

Solution code:
total = 0
last = 5
for _ in range(int(input())):
    a = input().split()
    for i in range(3):
        a[i] = int(a[i])

    b = sorted(a)[::-1]
    if(last != a.index(b[0])):
        last = a.index(b[0])
        total += b[0]
    else:
        last = a.index(b[1])
        total += b[1]

    # print(last,total)
print(total)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
abc_list = []

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

pre_suma,pre_sumb,pre_sumc = abc_list[0][0],abc_list[0][1],abc_list[0][2]

if n == 1:
    print(max(pre_suma,pre_sumb,pre_sumc))
    sys.exit()

for i in range(1,n):
    a,b,c = abc_list[i][0],abc_list[i][1],abc_list[i][2]
    suma = a + max(pre_sumb,pre_sumc)
    sumb = b + max(pre_suma,pre_sumc)
    sumc = c + max(pre_suma,pre_sumb)
    pre_suma,pre_sumb,pre_sumc = suma,sumb,sumc
    print(suma,sumb,sumc)
print(max(suma,sumb,sumc))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':

	n = int(input())
	res = [[0 for i in range(0, 3)] for i in range(n)]

	for i in range(n):
		x, y, z =  map(int,input().split())
		res[i][0] = max(res[i-1][1], res[i-1][2])+x
		res[i][1] = max(res[i-1][0], res[i-1][2])+y
		res[i][2] = max(res[i-1][0], res[i-1][1])+z

	r = max(res[-1])
	print(r)

Submission status: Wrong Answer

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

dp = [[0] * 3] * N
for idx, val in enumerate(abc):
    a, b, c = val
    if idx == 0:
        dp[0] = val
    else:
        tmp = []
        tmp.append(max(dp[idx - 1][1] + a, dp[idx - 1][2] + a))
        tmp.append(max(dp[idx - 1][0] + b, dp[idx - 1][2] + b))
        tmp.append(max(dp[idx - 1][1] + c, dp[idx - 1][0] + c))
        dp[idx] = tmp
print(max(dp))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
summer = []
for i in range(N):
    summer.append(list(map(int, sys.stdin.readline().rstrip().split(" "))))
print(summer)

INF = float('inf')
DP = [[-INF for i in range(3)] for i in range(N)]
print(DP)


for i in range(N):
    if i == 0:
        DP[i] = summer[i]
    else:
        DP[i][0] = max(DP[i-1][1], DP[i-1][2]) + summer[i][0]
        DP[i][1] = max(DP[i-1][0], DP[i-1][2]) + summer[i][1]
        DP[i][2] = max(DP[i-1][0], DP[i-1][1]) + summer[i][2]

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

Submission status: Wrong Answer

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

INF = float('inf')
DP = [[-INF for i in range(3)] for i in range(N)]
print(DP)


for i in range(N):
    if i == 0:
        DP[i] = summer[i]
    else:
        DP[i][0] = max(DP[i-1][1], DP[i-1][2]) + summer[i][0]
        DP[i][1] = max(DP[i-1][0], DP[i-1][2]) + summer[i][1]
        DP[i][2] = max(DP[i-1][0], DP[i-1][1]) + summer[i][2]

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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][k] + A[i][j])
print(max(dp[N]))

Submission status: Wrong Answer

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

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][k] + A[i][j])
            print(dp)
print(max(dp[N]))

Submission status: Wrong Answer

Solution code:
N = int(input())
a, b, c = (list() for _ in range(3))
for n in range(N):
  i,j,k = map(int, input().split())
  a.append(i)
  b.append(j)
  c.append(k)
value = {0:a, 1:b, 2:c}

dp = dict()
dp[0] = {key: 0 for key in [0,1,2]}
exc = {key: sorted([(key+i)%3 for i in range(1,3)]) for key in range(3)}

for d in range(0, N):
    dp[d+1] = dict()
    for s in [0,1,2]:
        dp[d+1][s] = max([dp[d][e]+value[s][d] for e in exc[s]])
    
print(dp[N][max(dp[N])])

Submission status: Wrong Answer

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

# j={A=0,B=1,C=2}の添え字を使うことにする
dp = [[0]*3 for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:  # 前日と同じActivityは除外
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j]+ABC[i-1][k])

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
a=[0]*n
b=[0]*n
c=[0]*n
A=0
B=0
C=0
for i in range(n):
    a[i],b[i],c[i]=map(int,input().split())
dp=[0]*n
for j in range(n):
    if j==0:
        dp[j]=max(a[j],b[j],c[j])
        if dp[j]==a[j]:
            A=1
        elif dp[j]==b[j]:
            B=1
        else:
            C=1
    else:
        if A==1:
            dp[j]=max(dp[j-1]+b[j],dp[j-1]+c[j])
            A=0
            B=0
            C=0
        elif B==1:
            dp[j]=max(dp[j-1]+a[j],dp[j-1]+c[j])
            A=0
            B=0
            C=0
        else:
            dp[j]=max(dp[j-1]+a[j],dp[j-1]+b[j])
            A=0
            B=0
            C=0
        if dp[j]==dp[j-1]+a[j]:
            A=1
        elif dp[j]==dp[j-1]+b[j]:
            B=1
        else:
            C=1
print(dp[n-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
ABC=[list(map(int,input().split())) for _ in range(n)]

dp=np.zeros((n,3),int)
for i in range(n):
  for j in range(3):
    dp[i][j]=max(dp[i-1][(j+1)%3]+ABC[i][j], dp[i-1][(j+2)%3]+ABC[i][j])
print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
n= int(input())
active = [[0, 0, 0]] * n

for i in range(n):
  a, b, c = map(int, input().split(' '))
  active[i] = [a, b, c]

dp = [0] * n

# print(n, active, dp)

def chmin(arr, index_a, val):
  if arr[index_a] > val:
    arr[index_a] = val
    return True
  return False

def chmax(arr, index_a, val):
  if arr[index_a] < val:
    arr[index_a] = val
    return True
  return False

ans = 0
pre_active = None
for i in range(n):
  current_active = active[i]
  
  happy = 0
  tmp_preactive = 0
  for j in range(3):
    if pre_active == j:
      continue
    if happy < current_active[j]:
      happy = current_active[j]
      tmp_pre_active = j
  dp[i] = happy
  pre_active = tmp_pre_active

print(sum(dp))

Submission status: Wrong Answer

Solution code:
n = int(input())
a,b,c = 0,0,0
for _ in range(n):
    x, y, z = map(int, input().split())
    a,b,c = max(a,b)+z,max(a,c)+y,max(b,c)+x

print(max(a,b,c))

Submission status: Wrong Answer

Solution code:
n = int(input())
a,b,c = 0,0,0
for _ in range(n):
    x, y, z = map(int, input().split())
    a,b,c = max(y,z)+a,max(x,z)+b,max(x,y)+c

print(max(a,b,c))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
b=[0]*n
c=[0]*n
for i in range(n):
    a[i],b[i],c[i]=list(map(int,input().split()))
dpa=[100000000]*n
dpb=[100000000]*n
dpc=[100000000]*n
dpa[0]=0
dpb[0]=0
dpc[0]=0
for i in range(n-1):
    dpa[i+1]=max(dpb[i]+a[i+1],dpc[i]+a[i+1])
    dpb[i+1]=max(dpa[i]+b[i+1],dpc[i]+b[i+1])
    dpc[i+1]=max(dpa[i]+c[i+1],dpb[i]+c[i+1])


print(max(dpa[n-1],dpb[n-1],dpc[n-1]))

Submission status: Wrong Answer

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

dp=[0]*(n+1)
dp[1]=max(a[0],b[0],c[0])
for i in range(2,n+1):
    if dp[i-1]-dp[i-2]==a[i-2]:
        dp[i]=dp[i-1]+max(b[i-1],c[i-1])
    elif dp[i-1]-dp[i-2]==b[i-2]:
        dp[i]=dp[i-1]+max(a[i-1],c[i-1])
    else:
        dp[i]=dp[i-1]+max(a[i-1],b[i-1])
print(dp[n])

Submission status: Wrong Answer

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

dp=[10000000]*(n+1)
dp[0]=0
dp[1]=max(a[0],b[0],c[0])
for i in range(2,n+1):
    if dp[i-1]-dp[i-2]==a[i-2]:
        dp[i]=dp[i-1]+max(b[i-1],c[i-1])
    elif dp[i-1]-dp[i-2]==b[i-2]:
        dp[i]=dp[i-1]+max(a[i-1],c[i-1])
    else:
        dp[i]=dp[i-1]+max(a[i-1],b[i-1])
print(dp[n])

Submission status: Wrong Answer

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

for i in range(N-1):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            newscore = days[i+1][j] + scores[i][k]
            if newscore > scores[i+1][j]:
                scores[i+1][j] = newscore

print(max([score[-1] for score in scores]))

Submission status: Wrong Answer

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

def getmax3(li):
    if(li[0] < li[1]):
        if(li[1] < li[2]):
            return [li[2], 2]
        else:
            return [li[1], 1]
    else:
        return [li[0], 0]

def getmax2(li, num):
    if(num == 0):
        return [li[2], 2] if(li[1]<li[2]) else [li[1], 1]
    elif(num == 1):
        return [li[2], 2] if(li[0]<li[2]) else [li[0], 0]
    else: # num == 2
        return [li[1], 1] if(li[0]<li[1]) else [li[0], 0]

def Main(N, V):
    dp = [[0]*2]*N
    dp[0] = getmax3(V[0])
    for i in range(1, N):
        res = getmax2(V[i], dp[i-1][1])
        dp[i][0] = res[0] + dp[i-1][0]
        dp[i][1] = res[1]
    return dp[N-1][0]

def main():
    N = int(input())
    V = []
    for i in range(N):
        V.append(list(map(int, input().split())))
    print(Main(N, V))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
H=[]
for i in range(n):
    a,b,c=map(int,input().split())
    H.append([a,b,c])
ans=[0]*(n+1)
vv=0
q=4
for i in range(0,3):
    if vv<H[0][i]:
        vv=H[0][i]
        q=i
ans[0]=vv
for i in range(1,n):
    tmp=0
    vq=q
    for j in range(0,3):
        if j!=vq and tmp<H[i][j]:
            tmp=H[i][j]
            vcb=j
    q=vcb
    ans[i]=ans[i-1]+tmp

print(ans[n-1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

    dp = [0]*n
    tmp_choices = choices[:]
    x = max(tmp_choices[0])
    dp[0] = tmp_choices[0].index(x)
    tmp_choices[0][dp[0]] = 0
    happiness = x
    for i in range(1, n):
        tmp_choices[i][dp[i-1]] = 0
        v = max(tmp_choices[i])
        happiness += v
        index = tmp_choices[i].index(v)
        dp[i] = index
    
    print(happiness)


if __name__ == '__main__':
    vacation()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
c = []

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

q, w, r = a[0], b[0], c[0]
for i in range(1, n):
    q, w, r = q + max(b[i], c[i]), w + max(a[i], c[i]), r + max(a[i], b[i])
ans = max(q, w, r)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
c = []

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

q, w, r = 0, 0, 0
for i in range(n):
    q, w, r = q + max(b[i], c[i]), w + max(a[i], c[i]), r + max(a[i], b[i])
ans = max(q, w, r)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
option=[]
for i in range(N):
    option.append(input().split())
if N==1:
    print(max(option[0]))
    exit()
dp=[0]*N
dp_select=[0]*N
dp[0]=max(option[0])
dp_select=option[0].index(max(option[0]))
option[1][dp_select]="0"
#option[1].pop(dp_select)
for i in range(1,N):
    if i==0:continue
    dp[i] = max(option[i])
    dp_select=option[i].index(max(option[i]))
    if i!=N-1:
        option[i+1][dp_select]="0"
#print(option)
sum=0
for i in range(N):
    sum += int(dp[i])
#print(dp)
print(sum)

Submission status: Wrong Answer

Solution code:
def main(n, choices):
    results = [[0, 0, 0] for _ in range(n)]
    results[0] = choices[0]
    for i in range(1, n):
        results[i][0] = choices[i][0] + max(results[i - 1][1], results[i - 1][2])
        results[i][1] = choices[i][1] + max(results[i - 1][0], results[i - 1][2])
        results[i][2] = choices[i][2] + max(results[i - 1][0], results[i - 1][1])
    return max(results[-1])


if __name__ == '__main__':
    N = int(input())
    C = []
    for _ in range(N):
        C.append(list(map(int, input().split())))
    print(N, C)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [0]
    B = [0]
    C = [0]
    for i in range(N):
        a, b, c = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        C.append(c)
    dp = [[0 for _ in range(N+1)] for _ in range(3)]
    if max(A[1], B[1], C[1]) == A[1]:
        dp[0][1] = A[1]
    elif max(A[1], B[1], C[1]) == B[1]:
        dp[1][1] = B[1]
    else:
        dp[2][1] = C[1]

    for i in range(1, N):
        if max(dp[0][i], dp[1][i], dp[2][i]) == dp[0][i]:
            if B[i+1] < C[i+1]:
                dp[2][i+1] = dp[0][i] + C[i+1]
            elif B[i+1] > C[i+1]:
                dp[1][i+1] = dp[0][i] + B[i+1]
            elif i < N - 1 and B[i+2] > C[i+2]:
                dp[2][i+1] = dp[0][i] + C[i+1]
            else:
                dp[1][i+1] = dp[0][i] + B[i+1]

        elif max(dp[0][i], dp[1][i], dp[2][i]) == dp[1][i]:
            if A[i+1] < C[i+1]:
                dp[2][i+1] = dp[1][i] + C[i+1]
            elif A[i+1] > C[i+1]:
                dp[0][i+1] = dp[1][i] + A[i+1]
            elif i < N - 1 and A[i+2] > C[i+2]:
                dp[2][i+1] = dp[1][i] + C[i+1]
            else:
                dp[0][i+1] = dp[1][i] + A[i+1]

        else:
            if A[i+1] < B[i+1]:
                dp[1][i+1] = dp[2][i] + B[i+1]
            elif A[i+1] > B[i+1]:
                dp[0][i+1] = dp[2][i] + A[i+1]
            elif i < N - 1 and A[i+2] > B[i+2]:
                dp[1][i+1] = dp[2][i] + B[i+1]
            else:
                dp[0][i+1] = dp[2][i] + A[i+1]

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
a = [0 for i in range(N)]
b = [0 for i in range(N)]
c = [0 for i in range(N)]

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

# N = 3
# a = [0 for i in range(3)]
# b = [0 for i in range(3)]
# c = [0 for i in range(3)]
# a[0], b[0], c[0] = [10, 40, 70]
# a[1], b[1], c[1] = [20, 50, 80]
# a[2], b[2], c[2] = [30, 60, 90]

af = [0 for i in range(N)]
bf = [0 for i in range(N)]
cf = [0 for i in range(N)]

ab = [0 for i in range(N)]
bb = [0 for i in range(N)]
cb = [0 for i in range(N)]

af[0] = a[0]
bf[0] = b[0]
cf[0] = c[0]

ab[0] = -sys.maxsize - 1
bb[0] = -sys.maxsize - 1
cb[0] = -sys.maxsize - 1


if N > 1:
    af[1] = a[1] + max(bf[0], cf[0])
    bf[1] = b[1] + max(af[0], cf[0])
    cf[1] = c[1] + max(af[0], bf[0])

    ab[1] = a[1] + af[0]
    bb[1] = b[1] + bf[0]
    cb[1] = c[1] + cf[0]

for i in range(2,N):
    af[i] = a[i] + max(bf[i-1], cf[i-1], bb[i-1], cb[i-1])
    bf[i] = b[i] + max(af[i-1], cf[i-1], ab[i-1], cb[i-1])
    cf[i] = c[i] + max(af[i-1], bf[i-1], ab[i-1], bb[i-1])
    ab[i] = a[i] + af[i-1]
    bb[i] = b[i] + bf[i-1]
    cb[i] = c[i] + cf[i-1]

#print(af, bf, cf, ab, bb, cb)

print(max(af[N-1],bf[N-1],cf[N-1],ab[N-1],bb[N-1],cb[N-1]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 10 08:56:23 2019

@author: avina
"""

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

for i in range(1,n):
    for j in range(0,3):
        
        dp[i][j] = dp[i-1][j] + max(l[i][j-1],l[i][j-2])
if n > 1:
    ans = max(dp[-2]) + max(l[-1])
else:
    ans = max(dp[-1])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 10 08:56:23 2019

@author: avina
"""

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a,b,c=map(int,input().split())
dp=[max(a,b,c)]
prev=0
if(a>b and a>c):
    prev=0
elif(b>a and b>c):
    prev=1
else:
    prev=2
for i in range(1,N):
    dp.append(-1)
#print(prev)
for i in range(1,N):
    a,b,c=map(int,input().split())
    if(prev==2):
        #print("Here")
        dp[i]=max(dp[i-1]+a,dp[i-1]+b)
        if(dp[i]==dp[i-1]+a):
            prev=0
        else:
            prev=1
    elif (prev == 1):
        dp[i] = max(dp[i - 1] + a, dp[i - 1] + c)
        if (dp[i] == dp[i - 1] + a):
            prev = 0
        else:
            prev=2
    elif (prev == 0):
        dp[i] = max(dp[i - 1] + c, dp[i - 1] + b)
        if (dp[i] == dp[i - 1] + c):
            prev = 2
        else:
            prev=1
#print(dp)
print(dp[N-1])

Submission status: Wrong Answer

Solution code:
def run():
  N = int(input())
  abc_li = [[int(i) for i in input().split()] for n in range(N)]
  dp = [0] * N
  dp[0] = [(abc_li[0][k], k) for k in range(3)]
  for n in range(1, N):
    len_dp = len(dp[n-1])
    dp[n] = [(0, 0) for _ in range(len_dp)]
    for k in range(len_dp):
      value, pre_abc = dp[n-1][k] 
      for abc, abc_value in enumerate(abc_li[n]):
        if pre_abc == abc: continue
        if dp[n][k][0] == (value + abc_value):
          dp[n].append((value + abc_value, abc))
          continue
        dp[n][k] = max([dp[n][k], (value + abc_value, abc)],
                      key=lambda x:x[0])
    dp[n] = list(set(dp[n]))
  print(max(dp[-1])[0])
  
if __name__ == '__main__':
  run()

Submission status: Wrong Answer

Solution code:
def run():
  N = int(input())
  abc_li = [[int(i) for i in input().split()] for n in range(N)]
  dp = [[[0, 0] for i in range(3)] for _ in range(N)]
  dp[0] = [[abc_li[0][k], k] for k in range(3)]
  for n in range(1, N):
    for k in range(3):
      value, pre_abc = dp[n-1][k]
      for abc_value, abc in zip(abc_li[n], range(3)):
        if pre_abc == abc: continue
        dp[n][k] = max([dp[n][k], [value + abc_value, abc]],
                      key=lambda x:x[0])
  print(max(dp[-1])[0])
  
if __name__ == '__main__':
  run()

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = []
for _ in range(N):
    a,b,c = [int(x) for x in stdin.readline().rstrip().split()]
    data.append((a,b,c))

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
l=[0]*n
for i in range(n):
    l[i]=list(map(int,input().split()))
    l[i].sort()
#print(l)
ans1=0
ans2=0
for i in range(n):
    if i%2==0:
        ans1+=l[i][2]
        ans2+=l[i][1]
    else:
        ans1+=l[i][1]
        ans2+=l[i][2]
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
l=[0]*n
for i in range(n):
    l[i]=list(map(int,input().split()))
    l[i].sort()
#print(l)
ans1=0
ans2=0
for i in range(n):
    if i%2==0:
        ans1+=l[i][2]
        ans2+=l[i][1]
    else:
        ans1+=l[i][1]
        ans2+=l[i][1]
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
def perform(data):
    total = max(data[0])
    a = data[0].index(total)
    for i in range(1, len(data)):
        data[i][a] = 0
        b = max(data[i])
        total = total + b
        a = data[i].index(b)
    return total

data = []
N = int(input().strip())
for i in range(N):
    a = list(map(int, input().strip().split()))
    data.append(a)
#print(N)
#print(data)
print(perform(data))

Submission status: Wrong Answer

Solution code:
n = int(input())

hap = [[0] for i in range(n)]
for i in range(n):
  hap[i] = [int(i) for i in input().split()]
  
dp = [[0]*3 for i in range(n)]
for i in range(3):
  dp[0][i] = hap[0][i]
  
for i in range(1, n):
  for j in range(3):
    dp[i][j] = max(dp[i-1][j]+hap[i][(j+1)%3], dp[i-1][j]+hap[i][(j+2)%3])
print(max(dp[n-1]))

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    abc = []
    for _ in range(n):
        a, b, c = list(map(int, input().rstrip('\n').split()))
        abc.append(sorted([[a, 0], [b, 1], [c, 2]], reverse=True))
    an = [[0] * n for _ in range(3)]
    fq = [[0] * n for _ in range(3)]
    fq[0][0] = abc[0][0][1]
    an[0][0] = abc[0][0][0]
    fq[1][0] = abc[0][1][1]
    an[1][0] = abc[0][1][0]
    fq[2][0] = abc[0][2][1]
    an[2][0] = abc[0][2][0]

    for i in range(1, n):
        if fq[0][i-1] != abc[i][0][1]:
            an[0][i] = abc[i][0][0]
            fq[0][i] = abc[i][0][1]
        else:
            an[0][i] = abc[i][1][0]
            fq[0][i] = abc[i][1][1]

        if fq[1][i-1] != abc[i][0][1]:
            an[1][i] = abc[i][0][0]
            fq[1][i] = abc[i][0][1]
        else:
            an[1][i] = abc[i][1][0]
            fq[1][i] = abc[i][1][1]

        if fq[2][i-1] != abc[i][0][1]:
            an[2][i] = abc[i][0][0]
            fq[2][i] = abc[i][0][1]
        else:
            an[2][i] = abc[i][1][0]
            fq[2][i] = abc[i][1][1]

        if abc[i][0][0] == abc[i][1][0]:
            fq[0][i] = -1
            fq[1][i] = -1
            fq[2][i] = -1
    print(max(sum(an[0]), sum(an[1]), sum(an[2])))


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
import sys
import heapq

input = sys.stdin.readline
N = int(input())

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

dp = np.zeros((n, 3))

dp[0, :] = abc[0, :]

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

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

print(int(np.max(dp[-1, :])))

Submission status: Wrong Answer

Solution code:
# Atcoder Vacation
n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().strip().split())))
dp=[0]*n
maxhap=-1
ind = -1
for i in range(3):
	if a[0][i]>maxhap:
		ind = i
		maxhap=a[0][i]
dp[0] = maxhap
for i in range(1, n):
	maxhap=-1
	for j in range(3):
		if a[i][j] > maxhap and j!=ind:
			cind = j
			maxhap = a[i][j]
	ind = cind
	dp[i] = dp[i-1] + maxhap
print(dp[-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
la=[0]*N
lb=[0]*N
lc=[0]*N
for i in range(N):
  la[i],lb[i],lc[i]=map(int,input().split())
a=[la[0]]+[0]*(N-1)
b=[lb[0]]+[0]*(N-1)
c=[lc[0]]+[0]*(N-1)
for j in range(1,N):
  a[j]=max(b[j-1],c[j-1])+la[j-1]
  b[j]=max(a[j-1],c[j-1])+lb[j-1]
  c[j]=max(a[j-1],b[j-1])+lc[j-1]
print(max(a[-1],b[-1],c[-1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
abc=[[int(i) for i in input().split()] for j in range(n)] 
dp=[[abc[0][0],abc[0][1],abc[0][2]],[0,0,0]]

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

Submission status: Wrong Answer

Solution code:
n=int(input())
abc=[[int(i) for i in input().split()] for j in range(n)] 
dp=[[abc[0][0],abc[0][1],abc[0][2]],[0,0,0]]

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

Submission status: Wrong Answer

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

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

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

print(max(dp[N]))

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
abc=[list(map(int,input().split())) for i in range(n)]
happy=[[0,0,0] for i in range(n)]
happy[0]=abc[0]
print(happy)
for i in range(n-1):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            happy[i+1][k]=max(happy[i+1][k],happy[i][j]+abc[i+1][k])
    # print(happy)
print(max(happy[-1]))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

A = B = C = 0

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