Relay
InterviewTime limit1sMemory limit1024 MB
Choose three distinct members and their running order to minimize the relay time, where each runner has a sprint time A and a baton time B.
- Level
Medium6 of 10
- Topics
- Sorting, Dynamic programming
- Solved
- No attempts yet
Problem
JOI High School's track club has members, numbered from 1 to . Member () runs the 100 m sprint in msec, and has baton control ability .
The club will enter the 300 m relay at a national contest. Three members each run 100 m, and each runner passes the baton to the next. If the first runner is , the second is , and the third is (), the relay goes as follows.
- Runner runs 100 m, taking msec.
- Runner passes the baton to runner , taking msec.
- Runner runs 100 m, taking msec.
- Runner passes the baton to runner , taking msec.
- Runner runs 100 m, taking msec.
The record is therefore
As the coach, you choose three distinct members and decide their running order so that the record is as small as possible. Write a program that finds the minimum possible record for the 300 m relay.
Input
The first line contains . Each of the next lines contains and , separated by a space.
Output
Print one integer on a single line: the minimum possible record of the 300 m relay, in msec.
Constraints
- ()
- ()