37 lines
773 B
Python
37 lines
773 B
Python
import sys
|
|
|
|
input = sys.stdin.readline
|
|
|
|
maxCost = 1000
|
|
N = int(input())
|
|
R = []
|
|
G = []
|
|
B = []
|
|
|
|
for _ in range(N) :
|
|
r, g, b = map(int, input().split())
|
|
R.append(r)
|
|
G.append(g)
|
|
B.append(b)
|
|
|
|
result = []
|
|
|
|
for i in range(3) :
|
|
dpR = [maxCost if i != 0 else R[0]]
|
|
dpG = [maxCost if i != 1 else G[0]]
|
|
dpB = [maxCost if i != 2 else B[0]]
|
|
|
|
for n in range(1, N) :
|
|
r, g, b = R[n], G[n], B[n]
|
|
dpR.append(r + min(dpG[n-1], dpB[n-1]))
|
|
dpG.append(g + min(dpR[n-1], dpB[n-1]))
|
|
dpB.append(b + min(dpR[n-1], dpG[n-1]))
|
|
|
|
if i==0 :
|
|
result.append(min(dpG[N-1], dpB[N-1]))
|
|
elif i==1 :
|
|
result.append(min(dpR[N-1], dpB[N-1]))
|
|
else :
|
|
result.append(min(dpR[N-1], dpG[N-1]))
|
|
|
|
print(min(result)) |