subject

Aladdin and his Carpet Aladdin wants to travel around the world and will choose a circular path to fly on his magical carpet. The carpet needs enough magic to take him from one place to another. He knows that after traveling some distance, he can find a magic source that will enable the carpet to travel a further distance. There are n magical sources along the circular path numbered from 0 to n-1. Initially, the carpet has no magic and Aladdin can use a portal to jump to any magical source and start his journey. The carpet consumes units of magic equal to the units of distance travelled. He needs to choose a point to start his journey that will allow him to complete his journey. Determine the lowest index of the starting points from which Aladdin can start his journey and visit all of the places in the circular path in order. If there is no solution, return -1
For example, there are n 4 sources of magic along his route: magic [3, 2, 5, 4] and dist [2, 3, 4, 2]. The first attempt is starting at the first source, magic[0] = 3. He transports there without cost and collects 3 units of magic. The distance to the next point is dist[0] = 2. It takes 2 units of magic to get there and he collects magic[1] = 2 units upon arrival, so he has 3 - 2 2 3 units of magic after making his first carpet ride. Continuing along the journey:
3-dist[11magic[2] = 3 - 3 5
5 5-dist(2]magic[3] = 5 - 4 + 4=5
5-dist[3] 5-2 3
At this point, he is back to the first source. Because he can complete his journey starting at source magic[0], there is no reason to continue with the analysis so its index, 0, is returned. To illustrate a point from the same example, if he starts at position 2, where magic[1] 2 and dist[1] 3, he will not be able to proceed to the next point because the distance is greater than his magic units. Note that the list is circular, so from magic[3] in this example, the next source on the path is magic[0].
Function Description
Complete the function optimal Point in the editor below. The function must return an integer that denotes the minimum index of magic from which he can start a successful journey. If no such starting point exists, return -1
optimalPoint has the following parameter(s):
magic[magic[0],...magic[n-1]: an array of integers where magicli] denotes the amount of magic in the ith source.
dist[dist(01,..dist[n-1]}: an array of integers where dist[i] denotes the distance to the next magical source.

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:40, Serenitybella
When the pc version of the spreadsheet program became available, the ibm pc quickly became the top-selling personal computer?
Answers: 3
image
Computers and Technology, 22.06.2019 11:00, najerajulio
What is the foundation for proper monitoring, load balancing and routing in distributed systems
Answers: 3
image
Computers and Technology, 24.06.2019 02:10, sIatt
Consider the usual algorithm to convert an infix expression to a postfix expression. suppose that you have read 10 input characters during a conversion and that the stack now contains these symbols: (5 points) | | | + | | ( | bottom |_*_| now, suppose that you read and process the 11th symbol of the input. draw the stack for the case where the 11th symbol is
Answers: 2
image
Computers and Technology, 24.06.2019 04:30, NEUROPHARMACOLOGICAL
The ieee 802.11: defines standards for wireless local area network (wlan) communication protocols. identifies various computers or devices connected to a network. verifies any resource attached to another computer on a network that is different from the computer to which the user is logged on. connects multiple local area networks (lans) and wide area networks (wans).
Answers: 2
You know the right answer?
Aladdin and his Carpet Aladdin wants to travel around the world and will choose a circular path to f...

Questions in other subjects: