{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eFarmer John has gone to town to buy some farm supplies. Being a very efficient man, he always pays for his goods in such a way that the smallest number of coins changes hands, i.e., the number of coins he uses to pay plus the number of coins he receives in change is minimized. Help him to determine what this minimum number is.\u003c/p\u003e\u003cp\u003eFJ wants to buy \u003ci\u003eT\u003c/i\u003e (1 ≤ \u003ci\u003eT\u003c/i\u003e ≤ 10,000) cents of supplies. The currency system has \u003ci\u003eN\u003c/i\u003e (1 ≤ \u003ci\u003eN\u003c/i\u003e ≤ 100) different coins, with values \u003ci\u003eV\u003c/i\u003e\u003csub\u003e1\u003c/sub\u003e, \u003ci\u003eV\u003c/i\u003e\u003csub\u003e2\u003c/sub\u003e, ..., \u003ci\u003eV\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e (1 ≤ \u003ci\u003eV\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e ≤ 120). Farmer John is carrying \u003ci\u003eC\u003c/i\u003e\u003csub\u003e1\u003c/sub\u003e coins of value \u003ci\u003eV\u003c/i\u003e\u003csub\u003e1\u003c/sub\u003e, \u003ci\u003eC\u003c/i\u003e\u003csub\u003e2\u003c/sub\u003e coins of value \u003ci\u003eV\u003c/i\u003e\u003csub\u003e2\u003c/sub\u003e, ...., and \u003ci\u003eC\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e coins of value \u003ci\u003eV\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e (0 ≤ \u003ci\u003eC\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e ≤ 10,000). The shopkeeper has an unlimited supply of all the coins, and always makes change in the most efficient manner (although Farmer John must be sure to pay in a way that makes it possible to make the correct change).\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"Line 1: Two space-separated integers: \u003ci\u003eN\u003c/i\u003e and \u003ci\u003eT\u003c/i\u003e.\r\u003cbr\u003eLine 2: N space-separated integers, respectively \u003ci\u003eV\u003c/i\u003e\u003csub\u003e1\u003c/sub\u003e, \u003ci\u003eV\u003c/i\u003e\u003csub\u003e2\u003c/sub\u003e, ..., \u003ci\u003eV\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e coins (\u003ci\u003eV\u003c/i\u003e\u003csub\u003e1\u003c/sub\u003e, ...\u003ci\u003eV\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e)\r\u003cbr\u003eLine 3: N space-separated integers, respectively \u003ci\u003eC\u003c/i\u003e\u003csub\u003e1\u003c/sub\u003e, \u003ci\u003eC\u003c/i\u003e\u003csub\u003e2\u003c/sub\u003e, ..., \u003ci\u003eC\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e"}},{"title":"Output","value":{"format":"HTML","content":"Line 1: A line containing a single integer, the minimum number of coins involved in a payment and change-making. If it is impossible for Farmer John to pay and receive exact change, output -1."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3 70\r\n5 25 50\r\n5 2 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"Farmer John pays 75 cents using a 50 cents and a 25 cents coin, and receives a 5 cents coin in change, for a total of 3 coins used in the transaction."}}]}