#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#define LL long long
using namespace std;
char *month[]={ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov" , "Dec"};
LL md[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
LL n,m,s,t;
struct ORDER
{
LL hour,nub;
bool operator<(const ORDER &b) const
{
return hour<b.hour;
}
}order[3000];
struct Cost
{
LL cost,i;
Cost(){}
Cost(LL a,LL b){cost=a;i=b;}
};
LL geth(char *s,LL day,LL year,LL H)
{
LL m=0;
for(m=0;m<12;m++) if(strcmp(s,month[m])==0) break;
year-=2000;
if(m<2) year--;
day+=year/4;
if(year<0) day--;
if(m<2) year++;
return (year*365+md[m]+day)*24+H;
}
int main()
{
LL i,j,k;
//freopen("in.txt","r",stdin);
std::ios::sync_with_stdio(false);
for(i=1;i<13;i++) md[i]+=md[i-1];
char ms[10];
LL d,y,h;
while(cin>>n>>m)
{
if(n==0 && m==0) return 0;
for(i=0;i<n;i++)
{
cin>>ms>>d>>y>>h>>order[i].nub;
order[i].hour=geth(ms,d,y,h);
if(order[i].hour>=m) exit(5);
}
sort(order,order+n);
cin>>t>>s;
deque<Cost> dq;dq.clear();
LL cost,ans=0;
k=0;
for(i=0;i<m;i++)
{
cin>>cost;
if(order[k].hour-i>t) continue;
while(!dq.empty() && cost<dq.back().cost+s*(i-dq.back().i)) dq.pop_back();
dq.push_back(Cost(cost,i));
while(k<n && order[k].hour==i)
{
//while(!dq.empty() && i-dq.front().i>t) dq.pop_front();
ans+=(dq.front().cost+(i-dq.front().i)*s)*order[k].nub;
//cout<<dq.front().i<<endl;
k++;
if(k>n) exit(10);
}
}
cout<<ans<<endl;
}
return 0;
}
HDU 4122 单调队列
最新推荐文章于 2020-09-06 19:55:48 发布