练习三 Problem R

Problem Description
Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member has any small money, he takes all the coins and throws them into a piggy-bank. You know that this process is irreversible, the coins cannot be removed without breaking the pig. After a sufficiently long time, there should be enough cash in the piggy-bank to pay everything that needs to be paid. <br><br>But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs! <br>

Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing two integers E and F. They indicate the weight of an empty pig and of the pig filled with coins. Both weights are given in grams. No pig will weigh more than 10 kg, that means 1 <= E <= F <= 10000. On the second line of each test case, there is an integer number N (1 <= N <= 500) that gives the number of various coins used in the given currency. Following this are exactly N lines, each specifying one coin type. These lines contain two integers each, Pand W (1 <= P <= 50000, 1 <= W <=10000). P is the value of the coin in monetary units, W is it's weight in grams. <br>

Output
Print exactly one line of output for each test case. The line must contain the sentence "The minimum amount of money in the piggy-bank is X." where X is the minimum amount of money that can be achieved using coins with the given total weight. If the weight cannot be reached exactly, print a line "This is impossible.". <br>

Sample Input
3 10 110 2 1 1 30 50 10 110 2 1 1 50 30 1 6 2 10 3 20 4

Sample Output
The minimum amount of money in the piggy-bank is 60. The minimum amount of money in the piggy-bank is 100. This is impossible.

• 本文已收录于以下专栏：

指针练习--变量交换H

Description 注：本题只需要提交填写部分的代码 用指针变量对两个整数按从小到大排序。 #include int main() {     int *p1,*p2,*p;     int a...
• l769255844
• 2015年12月27日 16:56
• 331

专题三 Problem R

• ML_ACM
• 2016年05月31日 20:46
• 142

r入门练习（三）

R语言学习，后更答案。 第七章 字串符和因子 7.1   字符串 字符向量中的每个元素都是字符串，文本的基本单位是字符向量。字符向量可用c 函数创建。我们可以用单引号或双引号把字符串引用起来，只要...
• Sumri_Lin
• 2017年10月30日 18:52
• 111

练习三 Problem A

• ibingyu
• 2016年05月16日 17:55
• 906

练习三 Problem J

• ibingyu
• 2016年05月27日 21:46
• 97

练习三 Problem N

Problem Description 我们看到过很多直线分割平面的题目，今天的这个题目稍微有些变化，我们要求的是n条折线分割平面的最大数目。比如，一条折线可以将平面分成两部分，两条折线最多可以将平面...
• ibingyu
• 2016年05月28日 19:39
• 177

练习三 Problem C

• ibingyu
• 2016年05月16日 17:41
• 116

练习三 Problem V

Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that th...
• ibingyu
• 2016年05月29日 11:21
• 116

练习三 Problem W

Problem Description Speakless很早就想出国，现在他已经考完了所有需要的考试，准备了所有要准备的材料，于是，便需要去申请学校了。要申请国外的任何大学，你都要交纳一定的申请费...
• ibingyu
• 2016年05月31日 19:34
• 152

练习三 Problem E

Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. T...
• ibingyu
• 2016年05月28日 20:51
• 146

举报原因： 您举报文章：练习三 Problem R 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)