問題一覧 > 通常問題

No.974 By the Last Day

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 51
作問者 : 沙耶花 / テスター : shibh308
お気に入りにしたユーザー ProblemId : 3724 / 自分の提出
問題文最終更新日: 2020-05-07 20:08:30
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 234 (順位表) の他の問題:

Problem Statement

Sayaka has a one-sided crush on an upperclassman at her high school.
However, he will graduate $W$ weeks from now.
So she has decided to confess her feelings on the day of the graduation ceremony.

Initially, the upperclassman's fondness for Sayaka, quantified in points (hereafter called the affection), is 0 points, and Sayaka has 0 yen.
Counting this week as week 1, she will prepare for her confession during week 1, week 2, ..., week $W$.

For each $i$ ( $1 \le i \le W$ ), Sayaka must take exactly one of the following actions in week $i$.

  • Go to school
    • If she made a promise for a date in the previous week, the affection decreases by $10^{100}$ points.
    • If she did not make a promise for a date in the previous week, she meets the upperclassman and promises to go on a date the following week. However, when $i=W$, nothing happens.
  • Work a part-time job
    • If she made a promise for a date in the previous week, the affection decreases by $10^{100}$ points, and her money increases by $a_i$ yen.
    • If she did not make a promise for a date in the previous week, her money increases by $a_i$ yen.
  • Go on a date
    • If she made a promise for a date in the previous week, the affection increases by $b_i$ points, and her money decreases by $c_i$ yen.
    • If she did not make a promise for a date in the previous week, nothing happens.
Note that in the week before week 1, Sayaka has not made a promise for a date with the upperclassman.

The values of the affection and her money may become negative.
In particular, when her money is negative, she is in debt.
Debt does not grow on its own through interest, and having debt does not prevent her from going on dates,
but if she is in debt at the end of week $W$, Sayaka will be forced to leave high school before the upperclassman's graduation ceremony. (In this case, Sayaka cannot confess to him.)

Find the maximum possible value of the affection at the time Sayaka confesses to the upperclassman.

Input

$W$
$a_1\ b_1\ c_1$
$:$
$a_W\ b_W\ c_W$

  • $1\le W \le 52$
  • $1\le a_i,b_i,c_i \le 10^{12}$
  • All input values are integers.

Output

Output the answer.
Print a newline at the end.

Sample

Sample 1
Input
3
3 3 3
1 2 3
4 3 2
Output
3

This can be achieved by working a part-time job in week 1, going to school in week 2, and going on a date in week 3.

Sample 2
Input
6
2 3 2
1 4 1
1 1 3
1 3 2
1 4 2
2 4 4
Output
8

Sample 3
Input
4
15 15 20
15 100 15
5 15 100
5 5 35
Output
0

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。