To celebrate that WF-2018 will be held in PKU, Alice, Bob, and Cate are asked
to make
N cakes.
Every cake i needs to go through 3 steps in restrict order:
1. Alice mixes flour and water for ai minutes;
2. Bob carefully bakes it for bi minutes;
3. Cate makes cream decoration for ci minutes.
Since Cate wants to have different kinds of cakes, the third stepof any cake i
is always not less time-consuming than the second stepof any cake j. Also, it is
reasonable that once anyone starts to process a cake, the procedurecannotbestoppedthenberesumed.
Tohavethesecakesdoneassoonaspossible, theyneedyourhelp.
Input
There are several cases (less than15 cases).
The first line ofevery case contains an integer N (1 ≤ N ≤ 105)—thenumberof
cakes to prepare.
After that, N lines follow, each of them contains three integers ai, bi and ci
(1 ≤ i ≤ N; 0 <ai, bi, ci < 106)—timethat needs to be spent onthe three steps of
cake i respectively.
It is guaranteed thatfor any i and any j, bi is no greater than cj.
The input ends with N = 0.
Output
For every case, print ina single linethe least possible timeto make all cakes.
>ans=max(∑inai+min1≤i≤n(bi+ci),∑inci+min1≤i≤n(ai+bi))>
>
a
n
s
=
m
a
x
(
∑
i
n
a
i
+
m
i
n
1
≤
i
≤
n
(
b
i
+
c
i
)
,
∑
i
n
c
i
+
m
i
n
1
≤
i
≤
n
(
a
i
+
b
i
)
)
>
2017ACM-北京网络赛-F-HihoCode-1583-Cake2017ACM-北京网络赛-F-HihoCode-1583-CakeDescriptionInputOutputExamplesInputOutputProblem DescriptionSolutionCodeDescription To celebrate tha...