PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000003. Kỳ nghỉ (Vacation)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Kỳ nghỉ (Vacation)
Vacation
Source: AtCoder
Problem Statement
A student has days of vacation. On each day, the student must choose exactly one of three activities:
- Activity A earns happiness points on day .
- Activity B earns happiness points on day .
- Activity C earns happiness points on day .
The same activity cannot be chosen on two consecutive days. Total happiness is the sum of the points earned over all days.
Find the maximum possible total happiness.
Input
The first line contains , the number of vacation days.
Each of the next lines contains three integers , the happiness points for the three activities on day .
Output
Print one integer: the maximum achievable total happiness.
Subtasks
- Subtask 1 (20 points): ; (); (); ().
- Subtask 2 (30 points): ; (); (); ().
- Subtask 3 (50 points): ; (); (); ().
Examples
Input
3
10 40 70
20 50 80
30 60 90
Output
210
Explanation
An optimal choice is C on day 1 (), B on day 2 (), and C on day 3 (). Consecutive activities differ and the total is .