Tap here to switch tabs
Problem
Submissions

Problem: Minimum Costs Using the Train Line

Try to solve the Minimum Costs Using the Train Line problem.

Statement

A train route has n +1+ 1 stops numbered from 00 to n and consists of two parallel tracks: a regular route and an express route.

You are given two integer arrays regular and express of length n, where regular[i] and express[i] represent the cost to travel from stop i to stop i +1+ 1 on the regular route and the express route, respectively.

You are also given an integer expressCost, which represents the cost to transfer from the regular route to the express route.

You start at stop 00 on the regular route. At any stop, you can move according to the following rules:

  • Traveling from stop i to stop i +1+ 1 on the regular route costs regular[i].

  • Traveling from stop i to stop i +1+ 1 on the express route costs express[i].

  • Transferring from the regular route to the express route costs expressCost.

  • Transferring from the express route to the regular route costs 00.

Return an array costs of length n, where costs[i] is the minimum cost to reach stop i +1+ 1 starting from stop 00.

Note: Switching lines can happen before or after traveling to a stop. The transfer fee expressCost must be paid every time you switch from the regular route to the express route.

Constraints:

  • n ==== regular.length ==== express.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq regular[i], express[i], expressCost ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Costs Using the Train Line

Try to solve the Minimum Costs Using the Train Line problem.

Statement

A train route has n +1+ 1 stops numbered from 00 to n and consists of two parallel tracks: a regular route and an express route.

You are given two integer arrays regular and express of length n, where regular[i] and express[i] represent the cost to travel from stop i to stop i +1+ 1 on the regular route and the express route, respectively.

You are also given an integer expressCost, which represents the cost to transfer from the regular route to the express route.

You start at stop 00 on the regular route. At any stop, you can move according to the following rules:

  • Traveling from stop i to stop i +1+ 1 on the regular route costs regular[i].

  • Traveling from stop i to stop i +1+ 1 on the express route costs express[i].

  • Transferring from the regular route to the express route costs expressCost.

  • Transferring from the express route to the regular route costs 00.

Return an array costs of length n, where costs[i] is the minimum cost to reach stop i +1+ 1 starting from stop 00.

Note: Switching lines can happen before or after traveling to a stop. The transfer fee expressCost must be paid every time you switch from the regular route to the express route.

Constraints:

  • n ==== regular.length ==== express.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq regular[i], express[i], expressCost ≤105\leq 10^5