单调队列,裸的!!坑死了,说好的“All the orders are sorted by the time in increasing order. 呢,我就当成严格上升的序列了,于是就各种错。测试数据是有重复元素的!!!
//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<algorithm> #include<iostream> #include<cstring> #include<fstream> #include<sstream> #include<vector> #include<string> #include<cstdio> #include<bitset> #include<queue> #include<stack> #include<cmath> #include<map> #include<set> #define FF(i, a, b) for(int i=a; i<b; i++) #define FD(i, a, b) for(int i=a; i>=b; i--) #define REP(i, n) for(int i=0; i<n; i++) #define CLR(a, b) memset(a, b, sizeof(a)) #define debug puts("**debug**") #define LL long long #define PB push_back #define MP make_pair #define eps 1e-10 using namespace std; const int N = 3333; const int M = 111111; int order[N], tim[N], pay[M]; char month[15][5] = {"zero", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; int hav[15] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; char mo[5]; int p[M]; int n, m, t, s, y, h, r, d; map<string, int> mp; void pre() { int i; mp.clear(); for(i = 1; i <= 12; i ++) { mp[month[i]] = i; } } int get_tm(int m, int d, int y, int h) { int ret = 0, i; for(i = 0; i < y; i ++) { if(i % 4 == 0) ret += 366 * 24; else ret += 365 * 24; } for(i = 1; i < m; i ++) { ret += hav[i] * 24; if(i == 2 && y % 4 == 0) ret += 24; } ret += (d - 1) * 24 + h; return ret; } void input() { int i, j; for(i = 0; i < n; i ++) { scanf("%s%d%d%d%d", mo, &d, &y, &h, &r); order[i] = r; tim[i] = get_tm(mp[mo], d, y - 2000, h); } scanf("%d%d", &t, &s); for(i = 0; i < m; i ++) { scanf("%d", &pay[i]); } } void slove() { int l = 0, r = 0, i = 0, j = 0; LL ans = 0; p[r ++] = 0; while(i < m) { while(pay[i] <= pay[p[r - 1]] + (i - p[r - 1]) * s && r > l) r --; p[r ++] = i; while(i - p[l] > t) l ++; while(j < n && i == tim[j])ans += (pay[p[l]] + (i - p[l]) * (LL)s) * (LL)order[j], j ++; i ++; } printf("%I64d\n", ans); } int main() { //freopen("input.txt", "r", stdin); pre(); while(scanf("%d%d", &n, &m), n + m) { input(); slove(); } return 0; }