# 2013 AIO(Intermediate) 赛题

## Archery

Input File: archin.txt
Output File: archout.txt
Time Limit: 1 second

When you were young, you were awe-struck by the battle scene in The Lord of the Rings: The Two Towers. From then on, you were determined to become the greatest archer of all time. After years of training, you are finally at the International Archery Olympiad (IAO), in Auckland.

On each of the two days of the IAO, all contestants are given a score and ranked by that score. After the second day of competition, all contestants are given an overall score equal to the sum of their two scores and their overall rank is then calculated from this.

Day 1 Score Day 1 Rank Day 2 Score Day 2 Rank Overall Score Overall Rank Katniss Legolas Link Merida Robin 50 70 20 40 0 2 1 4 3 5 30 20 40 50 40 4 5 2 1 2 80 90 60 90 40 3 1 4 1 5

A contestant’s rank is equal to the number of competitors with strictly greater scores than theirs, plus one. In the above example, there are two overall scores strictly greater than Katniss’s, so her overall rank is (2+1)=3. There are no overall scores strictly greater than Legolas’s, so his overall rank is (0+1)=1. (Notice that Legolas and Merida are both ranked 1, as no one has a strictly greater score than either of them.)

Sick with anticipation of the results, you sneak a look at a judge’s laptop. The scores aren’t shown, nor is your overall rank, but you do manage to glimpse your first-day rank and your second-day rank. You want to work out what your overall rank could be.

Your task is to write a program which, given the number of contestants in the IAO and your rank on each day, determines your best and worst possible overall rank.

### Input

Your program should read from the file . The first and only line of input will contain three space-separated integers in this order:

• N: the total number of contestants in the IAO (including you)
• A: your rank on just the first day (between 1 and N)
• B: your rank on just the second day (between 1 and N)

### Output

Your program should write to the file . Your output file should contain one line with two integers, with exactly one space between them. The first integer is your best (i.e. smallest number) possible overall rank and the second integer is your worst (i.e. largest number) possible overall rank.

## The Troublesome Frog

Input File: frogin.txt
Output File: frogout.txt
Time Limit: 1 second

Bazza and Shazza do not like bugs. They wish to clear out all the bugs on their garden fence. They come up with a brilliant idea: they buy some sugar frogs and release them near the fence, letting them eat up all the bugs.

The plan is a great success and the bug infestation is gone. But strangely, they now have a sugar frog infestation. Instead of getting rid of the frogs, Bazza and Shazza decide to set up an obstacle course and watch the frogs jump along it for their enjoyment.

The fence is a series of N fence posts of varying heights. Bazza and Shazza will select three fence posts to create the obstacle course, where the middle post is strictly higher than the other two. The frogs are to jump up from the left post to the middle post, then jump down from the middle post to the right post. The three posts do not have to be next to each other as frogs can jump over other fence posts, regardless of the height of those other posts.

The difficulty of an obstacle course is the height of the first jump plus the height of the second jump. The height of a jump is equal to the difference in height between its two fence posts. Your task is to help Bazza and Shazza find the most difficult obstacle course for the frogs to jump.

### Input

Your program should read from the file . The file will describe a single fence.

• The first line of input will contain one integer N: the number of fence posts.
• The next N lines will each contain one integer hi: the height of the ith fence post.

You are guaranteed that there will be at least one valid obstacle course: that is, there will be at least one combination of three fence posts where the middle post is strictly higher than the other two.

### Output

Your program should write to the file . Your output file should contain one line with one integer: the greatest difficulty of any possible obstacle course.

## Save-It

Input File: savein.txt
Output File: saveout.txt
Time Limit: 1 second

The United Bakers of Australia (UBA) is once again in hot water. Profits have been crumbling recently due to a new tax on an invisible poisonous ingredient underpinning cake manufacturing. Rather than adapt their recipes to use healthier alternatives, the UBA has employed analysts from PwC (People with Cupcakes) to find a way to cut costs.

Upon inspection of UBA’s purchasing practices, the analysts found that when a group of ingredients is ordered, the cost of the group is rounded to the nearest 5 cents. That is, a group’s cost is the multiple of 5 that has the smallest difference with the sum of its ingredient costs.

For instance, two items costing 32c and 47c can be bought in separate groups for 30c and 45c, or 75c in total, whereas purchasing them in one group together would cost 80c (rounded up from 79c).

Your task is to put the required ingredients into groups for purchasing in order to minimise their total cost.

### Input

Your program should read from the file . The file will describe a single list of ingredients.

• The first line of input will contain one integer N: the number of ingredients.
• The next N lines each contain one integer ci: the cost of the ith ingredient in cents.

### Output

Your program should write to the file . Your output file should contain one line with one integer: the minimum total cost for the ingredients.