HDU 4122 单调队列

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值