nyoj--364--Tian Bogey horse racing

Source: Internet
Author: User
Tags rounds

Tian Bogey race time limit: theMs | Memory Limit:65535KB Difficulty:3
Describe
Here is a famous stories in Chinese.

"That's about 2300 years ago." General Tian Ji is a high official in the country Qi. He likes to play horse racing with the king and others. "

"Both of Tian and the king had three horses in different classes, namely, regular, plus, and super. The rule is to has three rounds in a match; Each of the horses must is used in one round. The winner of a single round takes and hundred silver dollars from the loser. "

"The Being the most powerful man in the country, the king had so nice horses, and each class he horse is better than Tian ' S. As a result, each time the king takes six hundred silver dollars from Tian. "

"Tian Ji is not happy on that, until he met Sun Bin, one of the most famous generals in Chinese history. Using a little trick due to Sun, Tian Ji brought home of hundred silver dollars and such a grace in the next match. "

"It is a rather simple trick. Using the He regular class horse race against the Super class from the king, they would certainly lose that round. But then he plus beat the King ' s regular, and his super beat the King's Plus. What's a simple trick. And how does your think of Tian Ji, the high ranked official in China? "

Were Tian Ji lives in nowadays, he'll certainly laugh at himself. Even more, were he sitting in the ACM contest right now, he could discover that the horse racing problem can be simply Viewe D as finding the maximum matching in a bipartite graph. Draw Tian ' s horses on one side, and the king's horses on the other. Whenever one of Tian ' s horses can beat one from the king, we draw a edge between them, meaning we wish to establish this Pair. Then, the problem of winning as many rounds as possible are just to find the maximum matching in this graph. If There is ties, the problem becomes more complicated, he needs to assign weights 0, 1, or-1 to all the possible edges, And find a maximum weighted perfect matching ...

However, the horse racing problem is a very special case of bipartite matching. The graph is decided by the speed of the horses---a vertex of higher speed always beat a vertex of lower speed. In this case, the weighted bipartite matching algorithm are a too advanced tool to deal with the problem.

In this problem, you is asked to the write a program to solve this special case of matching problem.
Input
The
input consists of many test cases. Each case starts with a positive an integer n (n <=) on the first line, which are the number of horses on each side. The next n integers on the second line is the speeds of Tian ' s horses. Then the next n integers in the third line is the speeds of the King ' s horses.
Output
For each
input case, output a line containing a single number, which are the maximum money Tian Ji'll get, in Silve R dollars.

Sample input
392 83 7195 87 74220 2020 20220 1922 18
Sample output
20000

Test instructions: Is Tian bogey horse racing story, but this race horse no longer is 3, and become a lot of only, if the field bogey lose will give others 200, win will take 200, draw will forget. Ask Tian bogey how much money can be taken.

Thinking: Consider this problem, is a standard of greed, how to achieve it? We think so;

1, we first compare the most ability, if T (Tian bogey) horse ability, then continue from the strong side of the comparison.

2, otherwise began to compare weak horse, if t weak horse ability is weaker or equal to K weak horse, let this horse and K horse race, Tian Bogey deliberately lose a game.

AC Code:



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

nyoj--364--Tian Bogey horse racing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.