{"id":145,"date":"2011-11-24T20:15:46","date_gmt":"2011-11-24T12:15:46","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=145"},"modified":"2012-03-03T20:16:24","modified_gmt":"2012-03-03T12:16:24","slug":"hdu-4122-alices-mooncake-shop","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/hdu-4122-alices-mooncake-shop\/","title":{"rendered":"HDU 4122. Alice&#8217;s mooncake shop"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>\u4f60\u6709\u4e00\u4e2a\u751f\u4ea7\u6708\u997c\u7684\u5de5\u5382\u3001\u6bcf\u5929\u7684\u751f\u4ea7\u6210\u672c\u90fd\u4e0d\u540c\u3001\u673a\u5668\u6bcf\u5929\u53ef\u4ee5\u751f\u4ea7\u65e0\u9650\u591a\u6708\u997c\uff0c \u8f93\u5165 M \u4e2a\u5c0f\u65f6\u3001\u4ee5\u53ca\u8fd9 M \u4e2a\u5c0f\u65f6\u5185\u5fb7\u6210\u672c\u3002<br \/>\n\u6708\u997c\u7684\u4fdd\u8d28\u671f\u4e3a T \u3001\u6bcf\u5c0f\u65f6\u7684\u7ef4\u62a4\u8d39\u7528\u4e3a S\u3002\u4ee5\u53ca n \u4e2a\u8ba2\u5355\uff0c\u6bcf\u4e2a\u8ba2\u5355\u8868\u793a ti \u65f6\u523b\u9700\u8981 ri \u5757\u6708\u997c\u3001\u6700\u5c0f\u5316\u751f\u4ea7\u6210\u672c\u3002<br \/>\n(. .. N <= 2500 .. .) ..\n\n<!--more--><\/p>\n<p>Tags: \u8d2a\u5fc3\u3001\u5355\u8c03\u961f\u5217<\/p>\n<h3>Analysis: <\/h3>\n<p>\u4e3b\u8981\u6ce8\u610f\u5230\u6bcf\u5929\u53ef\u4ee5\u751f\u4ea7\u65e0\u9650\u591a\u6708\u997c\u3002\uff08\u5426\u5219\u7684\u8bdd\u3002\u3002\uff09\u3002<br \/>\n\u56e0\u6b64\u53ea\u8981\u5728\u4fdd\u8d28\u671f\u8303\u56f4\u5185\u627e\u5230\u4e00\u4e2a\u6700\u4f4e\u6210\u672c\u5373\u53ef\u3002\u3002<\/p>\n<p>\u3002\u3002\u56e0\u4e3a N \u6bd4\u8f83\u5c0f\u3002\u3002\u6240\u4ee5\u53ef\u4ee5\u5728\u7ebf\u5904\u7406\u6bcf\u4e2a\u8bf7\u6c42\u3002\u3002<br \/>\n\u6ce8\u610f\u5c3d\u7ba1\u52a0\u5165\u4e86\u526a\u679d\u3002\u3002\u4e0b\u9762\u7684\u7b97\u6cd5\u8fd8\u662f\u4f1a\u5728 S = 0\uff0c T = M \u7684\u60c5\u51b5\u4e0b\u9000\u5316\u3002<br \/>\n\uff08\u4f46\u4f3c\u4e4e\u53ef\u4ee5\u4e13\u4e3a\u8fd9\u79cd\u60c5\u51b5\u6253\u4e00\u4e2a\u8865\u4e01\u3002\u3002\uff09<\/p>\n<pre class=\"brush: cpp; collapse: true; light: false; title: B; toolbar: true; notranslate\" title=\"B\">\r\n\/** ` Micro Mezzo Macro Flation -- Overheated Economy ., **\/\r\n\r\n#include &lt;algorithm&gt;\r\n#include &lt;iostream&gt;\r\n#include &lt;iomanip&gt;\r\n#include &lt;sstream&gt;\r\n#include &lt;cstring&gt;\r\n#include &lt;complex&gt;\r\n#include &lt;cstdio&gt;\r\n#include &lt;string&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;bitset&gt;\r\n#include &lt;queue&gt;\r\n#include &lt;stack&gt;\r\n#include &lt;cmath&gt;\r\n#include &lt;ctime&gt;\r\n#include &lt;list&gt;\r\n#include &lt;set&gt;\r\n#include &lt;map&gt;\r\n\r\nusing namespace std;\r\n\r\n#define REP(i, n) for (int i=0;i&lt;int(n);++i)\r\n#define FOR(i, a, b) for (int i=int(a);i&lt;int(b);++i)\r\n#define DWN(i, b, a) for (int i=int(b-1);i&gt;=int(a);--i)\r\n#define REP_1(i, n) for (int i=1;i&lt;=int(n);++i)\r\n#define FOR_1(i, a, b) for (int i=int(a);i&lt;=int(b);++i)\r\n#define DWN_1(i, b, a) for (int i=int(b);i&gt;=int(a);--i)\r\n#define REP_C(i, n) for (int n____=int(n),i=0;i&lt;n____;++i)\r\n#define FOR_C(i, a, b) for (int b____=int(b),i=a;i&lt;b____;++i)\r\n#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i&gt;=a____;--i)\r\n#define REP_N(i, n) for (i=0;i&lt;int(n);++i)\r\n#define FOR_N(i, a, b) for (i=int(a);i&lt;int(b);++i)\r\n#define DWN_N(i, b, a) for (i=int(b-1);i&gt;=int(a);--i)\r\n#define REP_1_C(i, n) for (int n____=int(n),i=1;i&lt;=n____;++i)\r\n#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i&lt;=b____;++i)\r\n#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i&gt;=a____;--i)\r\n#define REP_1_N(i, n) for (i=1;i&lt;=int(n);++i)\r\n#define FOR_1_N(i, a, b) for (i=int(a);i&lt;=int(b);++i)\r\n#define DWN_1_N(i, b, a) for (i=int(b);i&gt;=int(a);--i)\r\n#define REP_C_N(i, n) for (n____=int(n),i=0;i&lt;n____;++i)\r\n#define FOR_C_N(i, a, b) for (b____=int(b),i=a;i&lt;b____;++i)\r\n#define DWN_C_N(i, b, a) for (a____=int(a),i=b-1;i&gt;=a____;--i)\r\n#define REP_1_C_N(i, n) for (n____=int(n),i=1;i&lt;=n____;++i)\r\n#define FOR_1_C_N(i, a, b) for (b____=int(b),i=a;i&lt;=b____;++i)\r\n#define DWN_1_C_N(i, b, a) for (a____=int(a),i=b;i&gt;=a____;--i)\r\n\r\n#define DO(n) while(n--)\r\n#define DO_C(n) int n____ = n; while(n____--)\r\n#define TO(i, a, b) int s_=a&lt;b?1:-1,b_=b+s_;for(int i=a;i!=b_;i+=s_)\r\n#define TO_1(i, a, b) int s_=a&lt;b?1:-1,b_=b;for(int i=a;i!=b_;i+=s_)\r\n#define SQZ(i, j, a, b) for (int i=int(a),j=int(b)-1;i&lt;j;++i,--j)\r\n#define SQZ_1(i, j, a, b) for (int i=int(a),j=int(b);i&lt;=j;++i,--j)\r\n#define REP_2(i, j, n, m) REP(i, n) REP(j, m)\r\n#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)\r\n\r\n#define ALL(A) A.begin(), A.end()\r\n#define LLA(A) A.rbegin(), A.rend()\r\n#define CPY(A, B) memcpy(A, B, sizeof(A))\r\n#define INS(A, P, B) A.insert(A.begin() + P, B)\r\n#define ERS(A, P) A.erase(A.begin() + P)\r\n#define BSC(A, X) find(ALL(A), X) \/\/ != A.end()\r\n#define CTN(T, x) (T.find(x) != T.end())\r\n#define SZ(A) int(A.size())\r\n#define PB push_back\r\n#define MP(A, B) make_pair(A, B)\r\n\r\n#define Rush int T____; RD(T____); DO(T____)\r\n#pragma comment(linker, &quot;\/STACK:36777216&quot;)\r\n#pragma GCC optimize (&quot;O2&quot;)\r\n#define Ruby system(&quot;ruby main.rb&quot;)\r\n#define Haskell system(&quot;runghc main.hs&quot;)\r\n#define Pascal system(&quot;fpc main.pas&quot;)\r\n\r\ntypedef long long LL;\r\ntypedef double DB;\r\ntypedef unsigned UINT;\r\ntypedef unsigned long long ULL;\r\n\r\ntypedef vector&lt;int&gt; VI;\r\ntypedef vector&lt;char&gt; VC;\r\ntypedef vector&lt;string&gt; VS;\r\ntypedef vector&lt;LL&gt; VL;\r\ntypedef vector&lt;DB&gt; VD;\r\ntypedef set&lt;int&gt; SI;\r\ntypedef set&lt;string&gt; SS;\r\ntypedef set&lt;LL&gt; SL;\r\ntypedef set&lt;DB&gt; SD;\r\ntypedef map&lt;int, int&gt; MII;\r\ntypedef map&lt;string, int&gt; MSI;\r\ntypedef map&lt;LL, int&gt; MLI;\r\ntypedef map&lt;DB, int&gt; MDI;\r\ntypedef map&lt;int, bool&gt; MIB;\r\ntypedef map&lt;string, bool&gt; MSB;\r\ntypedef map&lt;LL, bool&gt; MLB;\r\ntypedef map&lt;DB, bool&gt; MDB;\r\ntypedef pair&lt;int, int&gt; PII;\r\ntypedef pair&lt;int, bool&gt; PIB;\r\ntypedef vector&lt;PII&gt; VII;\r\ntypedef vector&lt;VI&gt; VVI;\r\ntypedef vector&lt;VII&gt; VVII;\r\ntypedef set&lt;PII&gt; SII;\r\ntypedef map&lt;PII, int&gt; MPIII;\r\ntypedef map&lt;PII, bool&gt; MPIIB;\r\n\r\n\r\n\/** I\/O Accelerator **\/\r\n\r\n\/* ... :&quot; We are I\/O Accelerator ... Use us at your own risk ;) ... &quot; .. *\/\r\n\r\ntemplate&lt;class T&gt; inline void RD(T &amp;);\r\ntemplate&lt;class T&gt; inline void OT(const T &amp;);\r\n\r\ninline int RD(){ int x; RD(x); return x;}\r\ntemplate&lt;class T&gt; inline T&amp; _RD(T &amp;x){ RD(x); return x;}\r\ninline void RC(char &amp;c){scanf(&quot; %c&quot;, &amp;c);}\r\ninline void RS(char *s){scanf(&quot;%s&quot;, s);}\r\n\r\ntemplate&lt;class T0, class T1&gt; inline void RD(T0 &amp;x0, T1 &amp;x1){RD(x0), RD(x1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2){RD(x0), RD(x1), RD(x2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3){RD(x0), RD(x1), RD(x2), RD(x3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void RD(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5, T6 &amp;x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);}\r\ntemplate&lt;class T0, class T1&gt; inline void OT(T0 &amp;x0, T1 &amp;x1){OT(x0), OT(x1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2){OT(x0), OT(x1), OT(x2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3){OT(x0), OT(x1), OT(x2), OT(x3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void OT(T0 &amp;x0, T1 &amp;x1, T2 &amp;x2, T3 &amp;x3, T4 &amp;x4, T5 &amp;x5, T6 &amp;x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}\r\n\r\ntemplate&lt;class T&gt; inline void RST(T &amp;A){memset(A, 0, sizeof(A));}\r\ntemplate&lt;class T0, class T1&gt; inline void RST(T0 &amp;A0, T1 &amp;A1){RST(A0), RST(A1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){RST(A0), RST(A1), RST(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){RST(A0), RST(A1), RST(A2), RST(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void RST(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}\r\n\r\ntemplate&lt;class T&gt; inline void CLR(T &amp;A){A.clear();}\r\ntemplate&lt;class T0, class T1&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1){CLR(A0), CLR(A1);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){CLR(A0), CLR(A1), CLR(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void CLR(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}\r\ntemplate&lt;class T&gt; inline void CLR(T &amp;A, int n){REP(i, n) CLR(A&#x5B;i]);}\r\ntemplate&lt;class T&gt; inline void FLC(T &amp;A, int x){memset(A, x, sizeof(A));}\r\ntemplate&lt;class T0, class T1&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, int x){FLC(A0, x), FLC(A1, x);}\r\ntemplate&lt;class T0, class T1, class T2&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2){FLC(A0), FLC(A1), FLC(A2);}\r\ntemplate&lt;class T0, class T1, class T2, class T3&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3){FLC(A0), FLC(A1), FLC(A2), FLC(A3);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5);}\r\ntemplate&lt;class T0, class T1, class T2, class T3, class T4, class T5, class T6&gt; inline void FLC(T0 &amp;A0, T1 &amp;A1, T2 &amp;A2, T3 &amp;A3, T4 &amp;A4, T5 &amp;A5, T6 &amp;A6){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5), FLC(A6);}\r\n\r\ntemplate&lt;class T&gt; inline void SRT(T &amp;A){sort(ALL(A));}\r\ntemplate&lt;class T, class C&gt; inline void SRT(T &amp;A, C B){sort(ALL(A), B);}\r\n\r\n\r\n\r\n\r\n\/** Add - On **\/\r\n\r\nconst int MOD = 1000000007;\r\nconst int INF = 0x7fffffff;\r\nconst DB EPS = 1e-6;\r\nconst DB OO = 1e15;\r\nconst DB PI = acos(-1.0);\r\n\r\n\/\/ &lt;&lt;= ` 0. Daily Use .,\r\n\r\ntemplate&lt;class T&gt; inline void checkMin(T &amp;a,const T b){if (b&lt;a) a=b;}\r\ntemplate&lt;class T&gt; inline void checkMax(T &amp;a,const T b){if (b&gt;a) a=b;}\r\ntemplate &lt;class T, class C&gt; inline void checkMin(T&amp; a, const T b, C c){if (c(b,a)) a = b;}\r\ntemplate &lt;class T, class C&gt; inline void checkMax(T&amp; a, const T b, C c){if (c(a,b)) a = b;}\r\ntemplate&lt;class T&gt; inline T min(T a, T b, T c){return min(min(a, b), c);}\r\ntemplate&lt;class T&gt; inline T max(T a, T b, T c){return max(max(a, b), c);}\r\ntemplate&lt;class T&gt; inline T sqr(T a){return a*a;}\r\ntemplate&lt;class T&gt; inline T cub(T a){return a*a*a;}\r\nint Ceil(int x, int y){return (x - 1) \/ y + 1;}\r\n\r\n\/\/ &lt;&lt;= ` 1. Bitwise Operation .,\r\n\r\ninline bool _1(int x, int i){return x &amp; 1&lt;&lt;i;}\r\ninline int _1(int i){return 1&lt;&lt;i;}\r\ninline int _U(int i){return _1(i) - 1;};\r\n\r\ninline int count_bits(int x){\r\n    x = (x &amp; 0x55555555) + ((x &amp; 0xaaaaaaaa) &gt;&gt; 1);\r\n    x = (x &amp; 0x33333333) + ((x &amp; 0xcccccccc) &gt;&gt; 2);\r\n    x = (x &amp; 0x0f0f0f0f) + ((x &amp; 0xf0f0f0f0) &gt;&gt; 4);\r\n    x = (x &amp; 0x00ff00ff) + ((x &amp; 0xff00ff00) &gt;&gt; 8);\r\n    x = (x &amp; 0x0000ffff) + ((x &amp; 0xffff0000) &gt;&gt; 16);\r\n    return x;\r\n}\r\n\r\ntemplate&lt;class T&gt; inline T low_bit(T x) {\r\n    return x &amp; -x;\r\n}\r\n\r\ntemplate&lt;class T&gt; inline T high_bit(T x) {\r\n    T p = low_bit(x);\r\n    while (p != x) x -= p, p = low_bit(x);\r\n    return p;\r\n}\r\n\r\n\/\/ &lt;&lt;= ` 2. Modular Arithmetic Basic .,\r\n\r\ninline void INC(int &amp;a, int b){a += b; if (a &gt;= MOD) a -= MOD;}\r\ninline int sum(int a, int b){a += b; if (a &gt;= MOD) a -= MOD; return a;}\r\ninline void DEC(int &amp;a, int b){a -= b; if (a &lt; 0) a += MOD;}\r\ninline int dff(int a, int b){a -= b; if (a &lt; 0) a  += MOD; return a;}\r\ninline void MUL(int &amp;a, int b){a = int((LL)a * b % MOD);}\r\ninline int pdt(int a, int b){return int((LL)a * b % MOD);}\r\n\r\n\r\n\/\/ &lt;&lt;= ' 0. I\/O Accelerator interface .,\r\n\r\ntemplate&lt;class T&gt; inline void RD(T &amp;x){\r\n    \/\/cin &gt;&gt; x;\r\n    scanf(&quot;%d&quot;, &amp;x);\r\n    \/\/char c; for (c = getchar(); c &lt; '0'; c = getchar()); x = c - '0'; for (c = getchar(); c &gt;= '0'; c = getchar()) x = x * 10 + c - '0';\r\n    \/\/char c; c = getchar(); x = c - '0'; for (c = getchar(); c &gt;= '0'; c = getchar()) x = x * 10 + c - '0';\r\n\r\n}\r\n\r\nint ____Case;\r\ntemplate&lt;class T&gt; inline void OT(const T &amp;x){\r\n    \/\/cout &lt;&lt; x &lt;&lt; endl;\r\n    printf(&quot;%.4lf\\n&quot;, x);\r\n    \/\/printf(&quot;%.2lf\\n&quot;, x);\r\n    \/\/printf(&quot;Case %d: %d\\n&quot;, ++____Case, x);\r\n}\r\n\r\n\r\n#define For_each(it, A) for (SII::iterator it = A.begin(); it != A.end(); ++it)\r\n\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst char Month&#x5B;12]&#x5B;4] = {&quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;, &quot;Apr&quot;, &quot;May&quot;, &quot;Jun&quot;, &quot;Jul&quot;, &quot;Aug&quot;, &quot;Sep&quot;, &quot;Oct&quot;, &quot;Nov&quot;, &quot;Dec&quot;};\r\nconst int Days&#x5B;12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};\r\n\r\n\r\n\r\nconst int N = 2509, M = 100009;\r\n\r\nint c&#x5B;M], t&#x5B;N], r&#x5B;N], T, S;\r\nint n, m;\r\n\r\nchar str&#x5B;4]; int d, y;\r\n#define h t&#x5B;x]\r\nint leap(int y){\r\n    return y % 400 == 0 || y % 4 == 0 &amp;&amp; y % 100 != 0;\r\n}\r\n\r\nvoid get_order(int x){\r\n    RS(str); RD(d, y); RD(h, r&#x5B;x]);\r\n\r\n    FOR(i, 2000, y){\r\n        if (leap(i)) h += 366 * 24;\r\n        else h += 365 * 24;\r\n    }\r\n\r\n    REP(i, 12) {\r\n        if (!strcmp(Month&#x5B;i], str)) break;\r\n        if (i == 1) h += 24 * (leap(y) ? 29 : 28);\r\n        else h += 24 * Days&#x5B;i];\r\n    }\r\n\r\n    h += 24 * (d - 1);\r\n}\r\n\r\nint main(){\r\n\r\n    \/\/freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n\r\n    while (scanf(&quot;%d %d&quot;, &amp;n, &amp;m) != EOF &amp;&amp; n){\r\n\r\n        REP(i, n) get_order(i); RD(T, S); REP(i, m) RD(c&#x5B;i]);\r\n\r\n        LL ans = 0; REP(i, n){\r\n            LL s = 0, cur = INF; DWN_1_C(j, t&#x5B;i], max(0, t&#x5B;i] - T)){\r\n                if (s &gt; cur) break; checkMin(cur, s + c&#x5B;j]);\r\n                s += S;\r\n            }\r\n            ans += cur * r&#x5B;i];\r\n        }\r\n\r\n        cout &lt;&lt; ans &lt;&lt; endl;\r\n    }\r\n}\r\n<\/pre>\n<h3>External link: <\/h3>\n<p><a href=\"http:\/\/acm.hdu.edu.cn\/showproblem.php?pid=4122\">http:\/\/acm.hdu.edu.cn\/showproblem.php?pid=4126<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: \u4f60\u6709\u4e00\u4e2a\u751f\u4ea7\u6708\u997c\u7684\u5de5\u5382\u3001\u6bcf\u5929\u7684\u751f\u4ea7\u6210\u672c\u90fd\u4e0d\u540c\u3001\u673a\u5668\u6bcf\u5929\u53ef\u4ee5\u751f\u4ea7\u65e0\u9650\u591a\u6708\u997c\uff0c \u8f93\u5165 M \u4e2a\u5c0f\u65f6\u3001\u4ee5\u53ca\u8fd9 M \u4e2a\u5c0f\u65f6\u5185\u5fb7\u6210\u672c\u3002 \u6708\u997c\u7684\u4fdd\u8d28\u671f\u4e3a T \u3001\u6bcf\u5c0f\u65f6\u7684\u7ef4\u62a4\u8d39\u7528\u4e3a S\u3002\u4ee5\u53ca n \u4e2a\u8ba2\u5355\uff0c\u6bcf\u4e2a\u8ba2\u5355\u8868\u793a ti \u65f6\u523b\u9700\u8981 ri \u5757\u6708\u997c\u3001\u6700\u5c0f\u5316\u751f\u4ea7\u6210\u672c\u3002 (. .. N<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[47],"tags":[],"class_list":["post-145","post","type-post","status-publish","format-standard","hentry","category-hdu"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-2l","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=145"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/145\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}