P21954 [GeeksforGeeks] A guy with a mental problem1604
普及-
题目描述

A guy has to reach his home and does not want to be late. He takes train to reach home. He has a mental illness, so he always switches train at every station.
For eg: If he starts with train A then at station 2 he will switch his train to train B and so on. Similarly, if he starts with train B then he will switch to train A at station 2 and so on. Please help him to find the minimum total time he would take to reach his home.

Example 1:
Input:
N = 3
A[] = {2, 1, 2}
B[] = {3, 2, 1}
Output:
5
Explanation:
If he chose train A initially, then time to
reach home will be : 2 + 2 + 2 = 6
If he Chose train B initially, then time to
reach home will be : 3 + 1 + 1 = 5
5 is minimum hence the answer.

Your Task:
You don't need to read input or print anything. Your task is to complete the function minTime() which takes the array A[], B[] and its size N as inputs and returns the minimum total time in seconds to reach home.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Constraints:
1 ≤ N ≤ 10^{6}
1 ≤ Ai, Bi ≤ 10^{6}

输入格式

见题面

输出格式

见题面

样例输入
N = 3 A[] = {2, 1, 2} B[] = {3, 2, 1}
样例输出
5