Rice card Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) Total submission (s): 18610 Accepted Submission (s): 6498 Problem Description UESTC Department Canteen's rice card has a very strange design, that is, before the purchase to determine the balance. If the remaining amount on the card is greater than or equal to 5 yuan before the purchase of an item, the purchase must be successful (even if the balance is negative on the card after purchase), it cannot be purchased (even if the amount is sufficient). So we all want to try to keep the balance on the card to the minimum. One day, the canteen has n vegetables for sale, each vegetable can be purchased once. If you know the price of each vegetable and the balance on the card, ask at least how much of the balance on the card. Input Multiple sets of data. For each group of data: The first action is an integer n, which indicates the number of dishes. n<=1000. The second line consists of n positive integers representing the price per vegetable. The price does not exceed 50. The third line includes a positive integer m, which represents the balance on the card. m<=1000. N=0 indicates the end of the data. Output For each set of inputs, the output line contains an integer that represents the smallest possible balance on the card. Sample Input 1 50 5 10 1 2 3 2 1 1 2 3 2 1 50 0 Sample Output -45 32 Source UESTC 6th Programming Contest Online |