AIOC Banner

Problem: Pirates

Want to try solving this problem? You can submit your code online if you log in or register.


Pirates

Input File: piratein.txt
Output File: pirateout.txt
Time Limit: 1 second

Yarr! Welcome aboard the Black Pearl! I'm Captain Mia Swamp, and this is my First Matey, Growlybills. We've heard you're handy with these computing contraptions, so I'll make you a deal: help us out with a little problem, and we won't feed you to the sharks.

You're in? Thought so.


\includegraphics[width=10cm]{map_meta}


See that map yonder? That long, thin island there is the Isle of Obstaclewick. Boring place. All you need to know is that it's L nautical miles long from east to west, and so thin we all just say it has zero width.

Our ship, the Black Pearl, is sailing the north coast of the island, X nautical miles from the west point. See the other ship, the one sailing the south coast, Y nautical miles from the west point? That's the HMS Smallerout, our target. It may look like a wibbly-wobbly old thing, but it's carrying some of Britain's greatest treasures.

We can sail either way around the Isle of Obstaclewick, approaching the Smallerout from either side. What we want you to do is tell us which way is shorter. We don't want to overwork the... volunteers... in the galley. So that's your job, landlubber! Write us a program that calculates the shortest distance we have to sail to reach the Smallerout!

Constraints

To evaluate your solution, the judges will run your program against several different input files. All of these files will adhere to the following bounds:

Input

Your program should read from the file . The first line of this file will contain the integer L. The second line will contain the integer X, and the third line will contain the integer Y.

Output

Your program should write to the file . Your output file should consist of a single integer: the shortest distance the Black Pearl must travel to reach the HMS Smallerout, given in nautical miles.

Sample Input 1

6
4
1

Sample Output 1

5

Sample Input 2

10
10
10

Sample Output 2

0

Sample Input 3

9
2
7

Sample Output 3

9

Explanation

In the first case, the Black Pearl can either sail west around the Isle, with a total distance of 4+1=5 nautical miles, or east around the Isle, with a total distance of 2+5=7 nautical miles. Hence the shortest distance is 5 nautical miles.

\includegraphics[width=6cm]{map_sample1}

In the second case, both the Black Pearl and the HMS Smallerout are at the east point of the Isle. The distance between them is thus zero.

\includegraphics[width=6cm]{map_sample2}

In the third case, sailing in either direction around the Isle takes 9 nautical miles.

\includegraphics[width=6cm]{map_sample3}

Scoring

The score for each input scenario will be 100% if the correct answer is written to the output file, and 0% otherwise.
Don't disappoint or ye'll be walkin' the plank!

 


Privacy statement
© Australian Mathematics Trust 2001-2024

Contact: training@orac.amt.edu.au
Page generated: 20 April 2024,  3:55am AEST