RoadOrFlightEasy
Member SRM 468 · 2009-12-03 · by keshav_57
Problem Statement
You are given
Return the minimum amount of time in which the king can reach his queen.
Constraints
- N will be between 1 and 50, inclusive.
- roadTime will contain exactly N elements.
- flightTime will contain exactly N elements.
- Each element of roadTime and flightTime will be between 1 and 1000, inclusive.
- K will be between 0 and N, inclusive.
3
{4, 6, 7}
{1, 2, 3}
1
Returns: 13
All flightTimes here are less than roadTimes. However the king can choose only 1 flight. The are two possible optimal routes. City 0-->1, 1-->2 by road and 2-->3 by flight takes time 4 + 6 + 3 = 13 units. City 0-->1 by road, 1-->2 by flight and 2-->3 by road also takes time 4 + 2 + 7 = 13 units.
3
{4, 6, 7}
{1, 2, 3}
2
Returns: 9
Now the king is allowed to take 2 flights.
3
{4, 6, 7}
{1, 2, 3}
3
Returns: 6
Choose all 3 flights since flights are faster than roads.
3
{1, 2, 3}
{2, 3, 4}
2
Returns: 6
flightTime can be larger than roadTime. So the King may take fewer than K flights even though he is allowed to take K of them.
1
{1000}
{1}
0
Returns: 1000
Submissions are judged against all 146 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class RoadOrFlightEasy with a public method int minTime(int N, vector<int> roadTime, vector<int> flightTime, int K) · 146 test cases · 2 s / 256 MB per case