Consider yourself as the route planner working for Mumbai road transportation cooperation which has b bus stops. We are aware of the distance between all pairs of adjacent bus stops:
x1 is the distance between the 1st and the 2nd Bus stop,
x2 is the distance between the 2nd and the 3rd Bus stop,
. . .
xb - 1 is the distance between the (b- 1)th and the (b)th Bus stop,
xb is the distance between the bth and the 1st Bus stop.
Consider the buses travel along the circle line in both ways. Find the shortest distance between stops with numbers s and t.
Input Format
The number of Bus stops on the circle line is denoted in the first line containing the number .
The distances between the adjacent Bus stops are denoted in the second line containing b integers x1, x2, ..., xb.
The numbers of Bus stops are denoted in the third line containing two numbers s and t, the value of s & t. Find the shortest distance.
Constraints
b(3 ≤ b ≤ 100)
(1 ≤ xi ≤ 100)
(1 ≤ s, t ≤ b)
Output Format
Find and print the Shortest distances between s & t.
Sample Input :
4
2 3 4 9
1 3
Sample Output 0
5
Sample Input 1
4
5 8 2 100
4 1
Sample Output 1
15
What I have tried:
I HAVE TRIED THE JAV CODE AS:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[] ) throws Exception {
Scanner s = new Scanner(System.in);
}
if(s1>t){
for(int d = s1;d<=b;d++){
xi[d]++;
dist1=xi[d];
}
for(int e = s1-1;e>=t;e--){
xi[e]++;
dist2=xi[e];
}
if(dist1<dist2){
System.out.println(dist1);
}else
{
System.out.println(dist2);
}
}
}
}
}
WHEN I GO THROUGH THE TEST CASES I DONT KNOW WHERE AM I GOING WRONG...