用单调队列维护一个每天的最低单价。。。
Alice's mooncake shop
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2663 Accepted Submission(s): 645
Problem Description The Mid-Autumn Festival, also known as the Moon Festival or Zhongqiu Festival is a popular harvest festival celebrated by Chinese people, dating back over 3,000 years to moon worship in China's Shang Dynasty. The Zhongqiu Festival is held on the 15th day of the eighth month in the Chinese calendar, which is in September or early October in the Gregorian calendar. It is a date that parallels the autumnal equinox of the solar calendar, when the moon is at its fullest and roundest.
The traditional food of this festival is the mooncake. Chinese family members and friends will gather to admire the bright mid-autumn harvest moon, and eat mooncakes under the moon together. In Chinese, “round”(圆) also means something like “faultless” Z http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vciChsHJldWlvbqGxLAogc28gdGhlIHJvdW5kZXN0IG1vb24sIGFuZCB0aGUgcm91bmQgbW9vbmNha2VzIG1ha2UgdGhlIFpob25ncWl1IEZlc3RpdmFsIGEgZGF5IG9mIGZhbWlseSByZXVuaW9uLjxicj4KPGJyPgpBbGljZSBoYXMgb3BlbmVkIHVwIGEgMjQtaG91ciBtb29uY2FrZSBzaG9wLiBTaGUgYWx3YXlzIGdldHMgYSBsb3Qgb2Ygb3JkZXJzLiBPbmx5IHdoZW4gdGhlIHRpbWUgaXMgSyBvoa9jbG9jayBzaGFycCggSyA9IDAsMSwyIKGtLiAyMykgc2hlIGNhbiBtYWtlIG1vb25jYWtlcywgYW5kIFdlIGFzc3VtZSB0aGF0IG1ha2luZyBjYWtlcyB0YWtlcyBubyB0aW1lLiBEdWUgdG8gdGhlIGZsdWN0dWF0aW9uIG9mIHRoZSBwcmljZSBvZiB0aGUgaW5ncmVkaWVudHMsCiB0aGUgY29zdCBvZiBhIG1vb25jYWtlIHZhcmllcyBmcm9tIGhvdXIgdG8gaG91ci4gU2hlIGNhbiBtYWtlIG1vb25jYWtlcyB3aGVuIHRoZSBvcmRlciBjb21lcyxvciBzaGUgY2FuIG1ha2UgbW9vbmNha2VzIGVhcmxpZXIgdGhhbiBuZWVkZWQgYW5kIHN0b3JlIHRoZW0gaW4gYSBmcmlkZ2UuIFRoZSBjb3N0IHRvIHN0b3JlIGEgbW9vbmNha2UgZm9yIGFuIGhvdXIgaXMgUyBhbmQgdGhlIHN0b3JhZ2UgbGlmZSBvZiBhIG1vb25jYWtlIGlzIFQgaG91cnMuCiBTaGUgbm93IGFza3MgeW91IGZvciBoZWxwIHRvIHdvcmsgb3V0IGEgcGxhbiB0byBtaW5pbWl6ZSB0aGUgY29zdCB0byBmdWxmaWxsIHRoZSBvcmRlcnMuCgogCjxicj4KCklucHV0CgpUaGUgaW5wdXQgY29udGFpbnMgbm8gbW9yZSB0aGFuIDEwIHRlc3QgY2FzZXMuIDxicj4KRm9yIGVhY2ggdGVzdCBjYXNlOjxicj4KVGhlIGZpcnN0IGxpbmUgaW5jbHVkZXMgdHdvIGludGVnZXJzIE4gYW5kIE0uIE4gaXMgdGhlIHRvdGFsIG51bWJlciBvZiBvcmRlcnMuIE0gaXMgdGhlIG51bWJlciBvZiBob3VycyB0aGUgc2hvcCBvcGVucy4gPGJyPgpUaGUgbmV4dCBOIGxpbmVzIGRlc2NyaWJlIGFsbCB0aGUgb3JkZXJzLiBFYWNoIGxpbmUgaXMgaW4gdGhlIGZvbGxvd2luZyBmb3JtYXQ6PGJyPgo8YnI+Cm1vbnRoIGRhdGUgeWVhciBIIFI8YnI+Cjxicj4KSXQgbWVhbnMgdGhhdCBvbiBhIGNlcnRhaW4gZGF0ZSwgYSBjdXN0b21lciBvcmRlcnMgUiBtb29uY2FrZXMgYXQgSCBvoa9jbG9jay4gobBtb250aKGxIGlzIGluIHRoZSBmb3JtYXQgb2YgYWJicmV2aWF0aW9uLCBzbyBpdCBjb3VsZCBiZSA="Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov" or "Dec". H and R are all integers.
The next line contains T and S meaning that the storage life of a mooncake is T hours and the cost to store a mooncake for an hour is S.
Finally, M lines follow. Among those M lines, the i th line( i starts from 1) contains a integer indicating the cost to make a mooncake during the i th hour . The cost is no more than 10000. Jan 1st 2000 0 o'clock belongs to the 1 st hour, Jan 1st 2000 1 o'clock belongs to the 2 nd hour, …… and so on.
(0
The input ends with N = 0 an