{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\"\u003e\n\t\u003cp\u003e\r\nBefore ACM can do anything, a\u0026nbsp;budget must be prepared and the necessary\r\nfinancial support obtained. The main income for this action comes from\r\nIrreversibly Bound Money (IBM). The idea behind is simple. Whenever\r\nsome ACM member has any small money, he takes all the coins and throws them\r\ninto a piggy-bank. You know that this process is irreversible, the coins\r\ncannot be removed without breaking the pig. After a sufficiently long\r\ntime, there should be enough cash in the piggy-bank to pay everything that\r\nneeds to be paid.\r\n\r\n\u003c/p\u003e\u003cp\u003e\r\nBut there is a big problem with piggy-banks. It is not possible to\r\ndetermine how much money is inside. So we might break the pig into\r\npieces only to find out that there is not enough money. Clearly, we want to\r\navoid this unpleasant situation. The only possibility is to weigh the\r\npiggy-bank and try to guess how many coins are inside. Assume that we\r\nare able to determine the weight of the pig exactly and that we know\r\nthe weights of all coins of a given currency. Then there is some\r\nminimum amount of money in the piggy-bank that we can guarantee. Your task\r\nis to find out this worst case and determine the minimum amount of\r\ncash inside the piggy-bank. We need your help. No more prematurely\r\nbroken pigs!\r\n\r\n\u003c/p\u003e\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003eThe input consists of \u003cvar\u003eT\u003c/var\u003e test cases. The number of them (\u003cvar\u003eT\u003c/var\u003e) is given on\r\nthe first line of the input file.\r\nEach test case begins with a line containing two integers \u003cvar\u003eE\u003c/var\u003e and \u003cvar\u003eF\u003c/var\u003e. They\r\nindicate the weight of an empty pig and of the pig filled with coins. Both\r\nweights are given in grams. No pig will weigh more than 10 kg, that means\r\n\u003cvar\u003e1 \u0026lt;\u003d E \u0026lt;\u003d F \u0026lt;\u003d 10000\u003c/var\u003e. On the second line of each test\r\ncase, there is an integer number \u003cvar\u003eN\u003c/var\u003e\r\n(\u003cvar\u003e1 \u0026lt;\u003d N \u0026lt;\u003d 500\u003c/var\u003e) that gives the number of various\r\ncoins used in the given currency. Following this are exactly \u003cvar\u003eN\u003c/var\u003e lines,\r\neach specifying one coin type. These lines contain two integers each, \u003cvar\u003eP\u003c/var\u003eand \u003cvar\u003eW\u003c/var\u003e\r\n(\u003cvar\u003e1 \u0026lt;\u003d P \u0026lt;\u003d 50000\u003c/var\u003e, \u003cvar\u003e1 \u0026lt;\u003d W \u0026lt;\u003d10000\u003c/var\u003e).\r\n\u003cvar\u003eP\u003c/var\u003e is the value of the\r\ncoin in monetary units, \u003cvar\u003eW\u003c/var\u003e is it\u0027s weight in grams.\r\n\r\n\u003c/p\u003e\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003ePrint exactly one line of output for each test case. The line must contain\r\nthe\u0026nbsp;sentence \r\n\"\u003ccode\u003eThe minimum amount of money in the piggy-bank is \u003cvar\u003eX\u003c/var\u003e.\u003c/code\u003e\"\r\nwhere \u003cvar\u003eX\u003c/var\u003e is\r\nthe minimum amount of money that can be achieved using coins with\r\nthe given total weight. If the weight cannot be reached exactly,\r\nprint a\u0026nbsp;line \"\u003ccode\u003eThis is impossible.\u003c/code\u003e\".\r\n\r\n\u003c/p\u003e\u003ch3\u003eExample\u003c/h3\u003e\r\n\u003cpre\u003e\r\nSample Input:\r\n3\r\n10 110\r\n2\r\n1 1\r\n30 50\r\n10 110\r\n2\r\n1 1\r\n50 30\r\n1 6\r\n2\r\n10 3\r\n20 4\r\n\r\nSample output:\r\nThe minimum amount of money in the piggy-bank is 60.\r\nThe minimum amount of money in the piggy-bank is 100.\r\nThis is impossible.\r\n\u003c/pre\u003e\r\n\n\u003c/div\u003e"}}]}