Energy Coupons ------ ------- You are a computer living on the planet E++, and you buy your energy from Dave's Energy Emporium (DEE). Every- thing is fast on E++, and energy charges are computed for each second of use. DEE has somewhat high prices, but excellent rebates, delivered as follows. The rebate period is P seconds. Every P seconds DEE gives you P rebate coupons. You can use these any time in the next P seconds, but only one can be used per second. Often the total coupon worth is 20% of what you paid DEE in the last P seconds, so DEE's is a good price if you use the coupons. However, you have heard rumors of change at the top of DEE, and at the end of the current period, there is a surprise. Apparently Dave has been bought out by the Devil, and the new coupons are different. First, different coupons are frequently for different amounts. Second, instead of each coupon expiring at the end of the new P second period, each expires after a different number of seconds in that period, with most expiring in less than P seconds. You find that if you simply used the coupons in order of expiration date, some of the coupons will expire before you can use them. So you need an algorithm to find the order in which you should use the coupons so that your total rebate is maximized. Input ----- For each test case, first a line that gives the test case name. Then a line containing just P giving the number of seconds in a period, which is also the number of coupons issued at the beginning of the period. Then P coupon lines, each of the form: V E where V is the value of the coupon and E is the expira- tion time. More specifically, you can use the coupon in second t of the new period if and only if t <= E, where the seconds are numbered t = 1, 2, ..., P. DEE has kindly sorted the coupons so their values are non-decreasing. 2 <= P <= 10,000,000 1 <= V <= 1,000,000 1 <= E <= P Input terminates with an end of file. The test case name line is at most 80 characters. Output ------ For each test case, first an exact copy of the test case name line. Then a line containing just best-rebate OUT OF total-value where `best-rebate' is the maximum rebate you can achieve given the coupon values and expiration times, and `total-value' is the sum of the values of all the coupons, what you would have received if there were no expiration times. Note that your rebate is not limited by the amount of energy you actually buy, as that is always more than the rebate. Sample Input ------ ----- -- SAMPLE 1 -- 3 2 2 3 2 4 2 -- SAMPLE 2 -- 3 2 2 3 1 4 3 -- SAMPLE 3 -- 10 5 6 5 2 6 4 6 7 6 3 7 9 8 10 8 1 9 3 9 2 Sample Output ------ ------ -- SAMPLE 1 -- 7 OUT OF 9 -- SAMPLE 2 -- 9 OUT OF 9 -- SAMPLE 3 -- 58 OUT OF 69 File: energy.txt Author: Bob Walton Date: Sat Oct 7 14:14:04 EDT 2017 The authors have placed this file in the public domain; they make no warranty and accept no liability for this file.